ghiboz
ghiboz

Reputation: 8003

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

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 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

Upvotes: 0

Views: 647

Answers (1)

vcsjones
vcsjones

Reputation: 141678

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.

Upvotes: 4

Related Questions