.NET Framework Bookmark and Share   
 index > .NET Base Class Library > Dialog on systemevents.sessionending
 

Dialog on systemevents.sessionending

Hi,

i'm working on a time recordingsystray-app. it should recognize a shutdown and provide the user a message box. the messagebox should be shown 5 seconds and if the user doesn't click a button in it, the app would mark the user as absent.

I'm able to catch the SystemEvents.SessionEnding Event and "cancel" it. the problem is that in win vista and 7 the message box doesn't appear because of the black overlay where all the processes are listet that is windows waiting for. the user has no possibilty to click anything.

there must be a way to handle this issue. office 2007 has the same mechanism to provide the user the possibilty to save their docs. in this case the "Would you like to save your file"-Dialog appears and there is no black overlay. after some seconds office is terminated - that would be ok so far.

i need a solution for xp,vista and 7.

have you any ideas?

thank you

the enviroment is .net 3.5.
jasmin d.
Prior to SessionEnding, the OS will try to close your forms. You can just use the CloseReason provided when your form is being closed. If CloseReason is WindowsShutDown, post your message, and handle that case.

You don't need to trap SystemEvents.SessionEnding for this. (At the point when SessionEnding is called, you won't have a good means of showing a message - which is the problem you're seeing).


Reed Copsey, Jr. - http://reedcopsey.com
Reed Copsey, Jr.
I just tried to do it this way - without success. the black overlay appears again and the user has no possibilty to handle the dialog box.
jasmin d.
Hi jasmin,

Where do you show the message box? If you show the message box in the SystemEvents.SessionEnding event handler function, the message box should appear before the full-screen shutdown UI.

static void SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e)
{
if (MessageBox.Show("Shuting down...", "Shutting...", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning)
== DialogResult.Cancel)
{
e.Cancel = true;
}
}

For more information about the application shutdown changes in Windows Vista/Windows 7, you can refer to this document:

Application Shutdown Changes in Windows Vista
http://msdn.microsoft.com/en-us/library/ms700677%28VS.85%29.aspx

Please feel free to let me know if you have any questions or concerns.

Best Regards,
Zhi-Xin




Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework!
Zhi-Xin Ye

You can use google to search for other answers

Custom Search

More Threads

• Nested dlls
• Dynamic Date
• Read/Write protected memory
• Screen Power ON/OFF
• Background Intelligent Transfert Service: list of error
• Collision Detection in C#
• Problem installing NET 2.0 on Windows NT
• why does IDictionary extend IEnumerable?
• casting generic list to generic list of interfaces
• ListViewItemSorter: why so slow?