Windows Develop Bookmark and Share   
 index > Windows Forms General > Delaying windows shutdown until process terminated
 

Delaying windows shutdown until process terminated

i have an exe which ftps xml order documents up to a server at 15 minute intervals, it then reads order acknowledgement xml documents and ftps them to this machine and processes them. The whole process takes 30 seconds to a minute tops, Had an order missed last night because i believe the machine was shut downand the process terminated half way through ie after the send but before the receive, is there any way of delayinig windows shutdown until my exe terminates? orsome other approach to solving this problem? problem only occurs on small 1-3 user siteswho turn their machines off before going home. thanks
ntsmith  Tuesday, January 22, 2008 10:13 AM

On the FormClosing event you do this:

Code Block

private void Form1_FormClosing(object sender, FormClosingEventArgs e)

{

if (e.CloseReason = CloseReason.WindowsShutDown)

e.Cancel = true;

}

This will not allow the application to close if windows is shutting down and therefore, the Windows shutdown will be cancelled.

Regards,

Fábio

Fábio Franco  Tuesday, January 22, 2008 10:32 AM

Oh, and I forgot, if you wish to resume app shutdown, use this:

Code Block
const long EWX_SHUTDOWN = 1;
const long EWX_REBOOT = 2;
const long EWX_FORCE = 4;
const long EWX_RESERVED = 0xFFFFFFFF;
[System.Runtime.InteropServices.DllImport("User32.dll")]
private static extern int ExitWindowsEx(long dwOptions, long dwReserved);

Then just call the ExitWindowsEx to resume windows shutdown when your operation is complete.
Hope this helps,
Regards,
Fábio
Fábio Franco  Tuesday, January 22, 2008 11:07 AM

On the FormClosing event you do this:

Code Block

private void Form1_FormClosing(object sender, FormClosingEventArgs e)

{

if (e.CloseReason = CloseReason.WindowsShutDown)

e.Cancel = true;

}

This will not allow the application to close if windows is shutting down and therefore, the Windows shutdown will be cancelled.

Regards,

Fábio

Fábio Franco  Tuesday, January 22, 2008 10:32 AM

Oh, and I forgot, if you wish to resume app shutdown, use this:

Code Block
const long EWX_SHUTDOWN = 1;
const long EWX_REBOOT = 2;
const long EWX_FORCE = 4;
const long EWX_RESERVED = 0xFFFFFFFF;
[System.Runtime.InteropServices.DllImport("User32.dll")]
private static extern int ExitWindowsEx(long dwOptions, long dwReserved);

Then just call the ExitWindowsEx to resume windows shutdown when your operation is complete.
Hope this helps,
Regards,
Fábio
Fábio Franco  Tuesday, January 22, 2008 11:07 AM

great thanks
ntsmith  Tuesday, January 22, 2008 11:29 AM

You can use google to search for other answers

Custom Search

More Threads

• Datagridview hierarchy structure
• WebBrowser control has problems navigating to a # fragment
• login to the windows form application
• custom control does not appear in toolbox
• GUI permissions on controls
• MessageBox usage causes error: namespace does not exisit in the namespace System
• Access Controls or Variables on other forms
• ContextSwitchDeadlock was detected
• Code for adding new entry to Access DB not working (Vb6 to Vb.Net 2005)
• Transfer files between server and client over internet