开发者

c# windows can't close the app in the shutdown

开发者 https://www.devze.com 2023-04-04 06:41 出处:网络
I have this problem: I built an application in c# .net 2.0 that is on the tray bar and everything works fine: if I click the close menu (that i\'ve added) I call Close(); of the main form and 开发者_

I have this problem: I built an application in c# .net 2.0 that is on the tray bar and everything works fine: if I click the close menu (that i've added) I call Close(); of the main form and 开发者_StackOverflow社区everything is ok. my problem is: if a person shutdown the pc without closing my application, windows seems to be not able to close this program and the shutdown routine is breaked.

a note: in my app I use a BackgroundWorker.

thanks in advance


If your application is doing something that is stopping windows from shutting down properly, you should handle the SystemEvents.SessionEnding event in your application. This event is fired when the system is shutting down or the user is logging off.

In your event handler, do whatever is necessary to allow your application to be terminated gracefully, such as stopping all background workers / threads - etc.

0

精彩评论

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