Generally you should avoid blocking if possible. The optimal use of
asynchronous methods is to provide a callback which will execute once the
async operation is complete. This means no blocking on the calling thread.
Unfortunately the programming model is a little more complex. Jeffrey
Richter has a series of articles in MSDN magazine on how to make this model
a little more elegant.
Regards,
Brian Rasmussen [C# MVP]
"Taras_96" <(E-Mail Removed)> wrote in message
news:4e3e15d1-0ff1-4dc0-b1cf-(E-Mail Removed)...
Hi everyone,
The page at
http://en.csharp-online.net/CSharp_D...s_method_calls
states that EndInvoke will block execution on the current thread until
the asynchronous method has finished executing.
Another method described is waiting on a signal:
"The next technique is to block on the IAsyncResult object’s wait
handle. When the asynchronous method is complete, the IAsyncResult
object’s AsyncWaitHandle will be signaled. Then any thread waiting on
that handle will be awakened. Once awake, the thread can call the
IAsyncResult object’s EndInvoke method to receive the return value."
Is there any difference in the two methods? When would you use one or
the other. If anything the second option seems more complicated as it
requires an extra call in order to get the result.
Thanks
Taras