This is a question from the community. The Code will be retained for future response.
Using
System;
Using
System. componentmodel;
Using
System. Windows. forms;
Namespace
Windowsapplication4
...
{
/**/
///
<Summary>
///
Gui
///
</Summary>
Public
Partial
Class
Form1: Form
...
{
Public
Form1 ()
...
{
Initializecomponent ();
}
Private
Void
Button#click (
Object
Sender, eventargs E)
...
{
//
Working with subthreads
New
System. Threading. Thread (
New
System. Threading. threadstart (startdownload). Start ();
}
//
Start download
Public
Void
Startdownload ()
...
{
Downloader downloader
=
New
Downloader ();
Downloader. ondownloadprogress
+ =
New
Downloader. ddownloadprogress (downloader_ondownloadprogress );
Downloader. Start ();
}
//
Synchronously update the UI
Void
Downloader_ondownloadprogress (
Long
Total,
Long
Current)
...
{
If
(
This
. Invokerequired)
...
{
This
. Invoke (
New
Downloader. ddownloadprogress (downloader_ondownloadprogress ),
New
Object
[]
...
{Total, current}
);
}
Else
...
{
This
. Progressbar1.maximum
=
(
Int
) Total;
This
. Progressbar1.value
=
(
Int
) Current;
}
}
}
/**/
///
<Summary>
///
Download class
///
</Summary>
Public
Class
Downloader
...
{
//
Delegate
Public
Delegate
Void
Ddownloadprogress (
Long
Total,
Long
Current );
//
Event
Public
Event
Ddownloadprogress ondownloadprogress;
//
Start Simulation
Public
Void
Start ()
...
{
For
(
Int
I
=
0
; I
<
100
; I
++
)
...
{
If
(Ondownloadprogress
! =
Null
)
Ondownloadprogress (
100
, I );
System. Threading. thread. Sleep (
100
);
}
}
}
}