In multi-threaded programming, we often need to update the interface display in the working thread. In multithreading, it is wrong to call interface controls directly, invoke and begininvoke occur to solve this problem, so that you can safely update the interface display in multiple threads.
The correct method is to update the interface in the work thread.CodeEncapsulated as a method, called through invoke or begininvoke. The difference between the two is that one causes the worker thread to wait, while the other does not.
The so-called "one-side response operation, one-side node addition" can always be relative, so that the burden on the UI thread is not too great, because correct interface updates must always be done through the UI thread, what we need to do is to wrap most of the operations in the work thread, and put the pure interface updates into the UI thread for the purpose of reducing the burden on the UI thread.
Here is a simple example to illustrate how to use it. For example, when you start a thread, you want to update a textbox in the form in the thread method ..
Using system. Threading;
Public Delegate void myinvoke (string Str );
Private void btnstartthread_click (Object sender, eventargs E)
{
Thread thread = new thread (New threadstart (doword ));
Thread. Start ();
}
Public void doword ()
{
Myinvoke MI = new myinvoke (settxt );
Begininvoke (MI, new object [] {"ABC "});
}
Public void settxt (string Str)
{< br> txtreceive. Text + = STR + system. environment. newline;
}