Want to know the when the system shutdown or log off events in .Net Programmatically ? When you are writing an application which is running in back ground your application may withheld the log off,shutdown process and your system may not respond to these events.... when i got this problem in one of my project i came across this solution which worked for me have a look at below sample code this code checks the status and often you can programmatically catch those events and you can normally terminate your app allowing safe log off or shutdown of the system.....
private const int WM_CLOSE = 0x0010;
private const int WM_QUERYENDSESSION = 0x0011;
private const int WM_ENDSESSION = 0x0016;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_QUERYENDSESSION
|| m.Msg == WM_ENDSESSION)
{
//your Code here what you want to do in case of above event
//Kill the background running threads and process of your application
}
base.WndProc(ref m);
}
0 comments:
Post a Comment