C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Operating System »

Capture system logout event and show message to user


Posted Date: 26 Apr 2007    Resource Type: Code Snippets    Category: Operating System
Author: Balamurali BalajiMember Level: Diamond    
Rating: 1 out of 5Points: 10



This sample shows how to capture and cancel the windows logoff event from your application.


When the user log off the computer without closing your application, you may want to capture that event and give a chance to save all the data. To capture the logout event, you can subscribe to the SessionEndingEventHandler event in your application. You may want to give a message to the user or save your data or yu can even cancel the logout request. To cancel the windows logoff from your application, you simply have to set e.Cancel = true in the event handler SessionEndingEventHandler


//Place this code in Form_Load event
Microsoft.Win32.SystemEvents.SessionEnding += new Microsoft.Win32.SessionEndingEventHandler(SystemEvents_SessionEnding);

// Add this eventhandler in the main form of your application
void SystemEvents_SessionEnding(object sender, Microsoft.Win32.SessionEndingEventArgs e)
{
MessageBox.Show("Please close the application and then logout or shutdown!");
e.Cancel = true;
}



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Override deault Windows message Handler Wndproc in a PPC applciation.
Previous Resource: Find out Running Task Manager Process
Return to Discussion Resource Index
Post New Resource
Category: Operating System


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use