Asynchronous Programming

  • Thread starter Thread starter bernardpace
  • Start date Start date
B

bernardpace

Hi,

I am trying to get more familiar with asynchronous programming.

I was reading through the document found on the page:

http://msdn.microsoft.com/library/d...html/cpovrasynchronousprogrammingoverview.asp

Now, I read that 'Always call EndInvoke after your asynchronous call
completes'.

In case the EndInvoke(..) method is not called, what would be the
behaviour?

Also, in the section 'Polling for Asynchronous Call Completion', the
program given checks whether the asynchronous method terminated, to
call the EndInvoke(..) method after. This is being done in the
following way:

while(ar.IsCompleted == false) {
Thread.Sleep(10);
}

If I'm correct, this is not so efficient. Is there other effecient
ways how this can be done?


Can someone help me out.
Thanks in Advance
 
In case the EndInvoke(..) method is not called, what would be the
behaviour?

For the System.Windows.Forms.Control class: nothing, they don't need
the paired EndInvoke call. For other classes: undefined behavior. The
called thread might block, for example.
while(ar.IsCompleted == false) {
Thread.Sleep(10);
}

If I'm correct, this is not so efficient. Is there other effecient
ways how this can be done?

This is actually quite efficient. The condition is checked quickly,
and Thread.Sleep just puts the thread to sleep and lets other threads
execute. You might want to use a longer sleep duration, though.
 
Hi,

I am trying to get more familiar with asynchronous programming.

I was reading through the document found on the page:

http://msdn.microsoft.com/library/d...html/cpovrasynchronousprogrammingoverview.asp

Now, I read that 'Always call EndInvoke after your asynchronous call
completes'.

In case the EndInvoke(..) method is not called, what would be the
behaviour?

Though it's not officially stated there is an exception for the
ISynchronizeInvoke variants on the Control and Form classes. In all
other cases EndInvoke should be called.
 
Back
Top