I thought that calling BeginInvoke more than once on the same delegate instance would cause problems, but I tried it out and it works. Why is that?
Is the IAsyncResult object returned with each BeginInvoke called unique instead of each instance of the delegate?
In other words, do I only need one instance of the delegate to spawn multiple calls to its function?
Each call to
BeginInvoketriggers a new request onto the .net thread pool.It is perfectly acceptable to call
BeginInvokemultiple times. EachIAsyncResultobject is unique to that specific call toBeginInvoke.Just be careful to make sure that you make a matching call to
EndInvokefor everyBeginInvokecall you make to make sure the resources are cleaned up.(Note that each call does not necessarily equate to a thread.
BeginInvokepasses the requests to the thread pool, which may queue up the requests if all of the threads in the pool are already in use)