PC Review


Reply
Thread Tools Rate Thread

Asynchronous methods: EndInvoke versus Waiting on Handle

 
 
Taras_96
Guest
Posts: n/a
 
      2nd Jul 2008
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
 
Reply With Quote
 
 
 
 
Brian Rasmussen [C# MVP]
Guest
Posts: n/a
 
      3rd Jul 2008
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

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Determine underlying Object in Asynchronous EndInvoke(). Peter Microsoft C# .NET 2 28th Jul 2008 09:49 AM
Create my own asynchronous BeginXXXX methods and EndXXXX methods Varangian Microsoft C# .NET 2 15th May 2008 09:46 PM
EndInvoke can only be called once for each asynchronous operation. =?Utf-8?B?RW5kSW52b2tlIGNhbiBvbmx5IGJlIGNhbGxlZCBv Microsoft Dot NET Framework 1 24th May 2004 08:52 AM
EndInvoke can only be called once for each asynchronous operation. =?Utf-8?B?VW1lc2hh?= Microsoft Dot NET Framework 0 24th May 2004 08:41 AM
EndInvoke can only be called once for each asynchronous operation scott ocamb Microsoft Dot NET 1 24th Nov 2003 02:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:38 PM.