Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've been looking into async calls just recently. I found a pointer to an article with an <a href="http://msdn.microsoft.com/en-us/magazine/cc163467.aspx" rel="nofollow noreferrer">example implementation of an IAsyncResult</a> by respected author Jeffrey Richter. I learned a lot about how async calls work by studying this implementation.</p> <p>You might also see if you can download and examine the source code for the <code>System.Runtime.Remoting.Messaging.AsyncResult</code> you're specifically concerned with. Here's a <a href="http://blogs.msdn.com/sburke/archive/2008/01/16/configuring-visual-studio-to-debug-net-framework-source-code.aspx" rel="nofollow noreferrer">link to instructions on how to do this in Visual Studio</a>.</p> <p>To add a bit to JaredPar's good answers...</p> <p>1: I believe if you define a closure which can be assigned to a variable of type AsyncCallback (takes an IAsyncResult and returns void) it should work as you would expect a closure to work as that delegate, but I'm not sure if there could be scope issues. The originating local scope should have returned long before the callback gets invoked (that's what makes it an asynchronous operation), so bear that in mind with respect to references to local (stack) variables and how that will behave. Referencing member variables should be fine, I would think.</p> <p>2: I think from your comment that you may have misunderstood the answer to this one. In Jeffrey Richter's example implementation the wait handle is signaled <i>before</i> the callback is invoked. If you think about it, it has to be this way. Once it invokes the callback it loses control of the execution. Suppose the callback method throws an exception.... execution could unwind back past the method which invoked the callback and thus prevent it from ever later signaling the wait handle! So the wait handle needs to be signalled before callback is invoked. They're also much closer in time if done in that order than if it signals the wait handle only after the callback has returned.</p> <p>3: As JaredPar says, IsCompleted should be returning <code>true</code> <i>before</i> the callback and before the wait handle is signaled. This makes sense because if IsCompleted is false you would expect the call to <code>EndInvoke</code> to block, and the whole point of the wait handle (as with the callback) is to know when the result is ready and it <i>won't</i> block. So, first IsCompleted is set to <code>true</code>, then the wait handle is signalled, and then the callback is called. See how Jeffrey Richter's example does it. <i>However</i>, you probably should try to avoid assumptions about the order in which these three methods (polling, wait handle, callback) might detect the completion, because it's possible to implement them in a different order than expected.</p> <p>4: I can't help you there, except that you might find the answer by debugging into the framework source code for the implementation you're curious about. Or you could probably come up with an experiment to find out... or set up a good experiment and debug into the framework source to be really sure.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload