When you use BeginInvoke to call a delegate asynchronously, you can
pass it a AsyncCallback which gets called in the same ThreadPool
thread that runs the 'main' delegate, after the 'main' delegate
returns.
Why? What's the point?
If I want to run This() when That() is done, why wouldn't I just
BeginInvoke a delegate to "void Compound() {That(); This()}" ?
If I want to 'fire and forget' and have the callback call EndInvoke,
why wouldn't I just call ThreadPool.QueueUserWorkItem()?
Have anyone EVER passed anything but null, null as the last two
parameters to BeginInvoke?
<not-totally-stupid>
I did Google this, and I did see lots of sample code that
passes an AsyncCallback - but each and every one was either
a 'fire and forget' or a 'compound' situation.
</not-totally-stupid>
(I suppose it's easier to pass multiple params to an asynch delegate
than to save them to a tiny object that calls the delegate, and that
can then export a parameter-less method suitable for passing to
ThreadPool.QueueUserWorkItem, but you still have to supply a
AsyncCallback delegate to cast the IAsyncResult.AsyncState to the
right delegate type and EndInvoke the IAsyncResult. This doesn't save
much effort, if any, even under 1.1 (and, with anonymous methods, it's
dead simple to write an WaitCallback delegate that does nothing but
pass a bunch of params to a method.) I can't really believe that this
"multiple params" scenario is why every asynch call has this callback
option.)
--
www.midnightbeach.com