Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is EndInvoke() optional, sort-of optional, or definitely not optional?

I've read conflicting opinions as to whether every BeginInvoke() has to be matched by an EndInvoke(). Are there any leaks or other problems associated with NOT calling EndInvoke()?

like image 830
endian Avatar asked Feb 10 '09 15:02

endian


2 Answers

Delegate.EndInvoke is documented as a thou shalt call this (i.e. necessary - else leaks happen) - from msdn:

Important Note

No matter which technique you use, always call EndInvoke to complete your asynchronous call.

Control.EndInvoke is OK to ignore for fire-and-forget methods - from msdn:

You can call EndInvoke to retrieve the return value from the delegate, if neccesary, but this is not required.

However - if you are using Delegate.BeginInvoke and don't want the result, consider using ThreadPool.QueueUserWorkItem instead - it'll make life a lot easier, and avoid the pain of IAsyncResult etc.

like image 198
Marc Gravell Avatar answered Sep 22 '22 19:09

Marc Gravell


EndInvoke is not optional.

More info here

like image 40
Luca Martinetti Avatar answered Sep 18 '22 19:09

Luca Martinetti