Search code examples
.netdelegatesiasyncresultasynchronous

EndInvoke's arguments


I have a delegate foo, I call BeginInvoke on it and retrieve the IAsyncResult into a var bar.

I then call EndInvoke(bar) and everything is happy.

Why do I have to pass bar to endinvoke? what exactly is going on that demands this? I realize Endinvoke is mandatory to clear possible resource leaks, but this parameter makes no sense...


Solution

  • No, it makes perfect sense. You could have invoked the delegate multiple times - how is EndResult meant to know which invocation you're talking about? The IAsyncResult is basically encapsulating the asynchronous task.

    If you've been looking at any of the newer stuff, think of IAsyncResult as a little bit like an opaque version of Task.