A question about "Safe, Simple Multithreading in Windows Forms, Part 1" on MSDN

J

Jeff Yang

These days,I have read the artile "Safe, Simple Multithreading in Windows
Forms, Part 1" on MSDN,and I also runed the example of it.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms06112002.asp
The question is In function void ShowProgress(string pi, int totalDigits,
int digitsSoFar);
if I use Invoke(showProgress, new object[] { pi, totalDigits,
digitsSoFar});the UI performs better(it responses to my minimize&restore
faster),and if I use BeginInvoke(showProgress, new object[] { pi,
totalDigits, digitsSoFar});,then the UI seems performs slower.
why Invoke is better than BeginInvoke?(As generally thinking,BeginInvoke
should be better than Invoke,because it works asynchronously).

thanks!
 
D

Dmitriy Lapshin [C# / .NET MVP]

Jeff,

Invoke(...) runs the passed delegate on the UI thread synchronously (that
is, the calling thread will block until the Invoke() call returns).

BeginInvoke(...) returns immediately and schedules the delegate to be run on
the UI thread.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top