I am writing a program for a company , I wrote a program for suppliers . Unfortunately , One of IT Managers saw that , employees don't close this program before shut down their computers and he said to me your application must close itself before shuting down . I told him , this is not a problem and windows close this program but he says I don't want to see (Windows [windows waiting for background programs to close]) .
After this I find this code :
static void SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e)
{
switch (e.Reason)
{
case SessionEndReasons.Logoff:
Application.Exit();
break;
case SessionEndReasons.SystemShutdown:
Application.Exit();
break;
}
}
and then add it to Form_Load :
SystemEvents.SessionEnding += SystemEvents_SessionEnding;
If you write a messagebox before Application.Exit() , It shows it without problem but , It doesn't work and I can see (windows waiting for background programs to close) again .
Why ?! Is there any problem in my code ?! Is there another way ?
thanks