Purpose:
Deliver the event that requires a long time to the subthread for processing, and continue to do what you should do.
Method:
Use event or delegate. To check whether the Sub-thread has been completed.
Public Delegate void callback ();
Public class waitcall
{
Private callback vfinished; // specify a delegate object.
Public void dolongtask (callback pcallback)
{
Vfinished = pcallback; // specifies the method to be triggered at the end.
Thread vthread = new thread (New threadstart (dothework); // execute this task through a subthread
Vthread. Start ();
}
Public void dothework ()
{
// Do the long work
// Set MSG to tell the work has been finished
Vfinished (); // method to bind to the Delegate
}
}
Public class mainapp
{
Public Void Do ()
{
Waitcall vwaitcall = new waitcall ();
Vwaitcall. dolongtask (dofinished); // execute this task
}
Private void dofinished ()
{
MessageBox. Show ("finished"); // After the task is completed, the subthread calls this method.
}
}
If an event is used, you can define an event. The type is the type of the delegate.