开发者

Proper use of IsDisposed in Windows Forms

开发者 https://www.devze.com 2022-12-17 08:14 出处:网络
I have a small win form app that consists 开发者_如何学运维of a form and a systray icon. When the user closes the app from the systray I get the ObjectDisposedException as some controls (task icon) s

I have a small win form app that consists 开发者_如何学运维of a form and a systray icon.

When the user closes the app from the systray I get the ObjectDisposedException as some controls (task icon) still try and access the main windows form.

I have tried wrapping the code that access the systray in a if(!this.IsDisposed) wrapper, however the check for this is always bypassed.

Am I missing something that I should be doing here? This seems quite trivial.

Thanks.


You're in control of what happens when the user closes the app. Close things in the right order (based on what forms/controls reference other forms/controls) and you can avoid this problem without hacking in IsDisposed checks.

0

精彩评论

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