开发者

EndInvoke() - optional or not?

An asynchronous question:

I've been reading over the internet LOTS of articles for and against Delegate.EndInvoke() being optional. Most of those articles are 4-5 years old. Lots of dead links.

Can anyone explain, in .NET 2.0 - is EndInvoke() indeed preventing an otherwise-inevitable memory leak, and if yes can you please specify what causes this leak?

On the same subject: If EndInvoke() is indeed a must - I find the best way to implement Fire-and-forget mechanism using a callback method that runs EndInvoke(). I'd love to hear f开发者_JAVA技巧rom anyone who thinks otherwise.

Thanks, O


For Delegate.EndInvoke, you should call it. For Control.EndInvoke, the WinForms team has said that you don't need to call it. I don't know about the equivalent for WPF, but I think it's a good idea to do so unless you've got a really good reason to believe you don't have to.

I have some "fire and forget" code for delegates in my threading article - about half way down (search for "fire").


From the msdn :

Always call EndInvoke to complete your asynchronous call.

I advice you to follow the guidelines, even if it works without leaks today, it may change tomorrow.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜