Monday, May 21, 2012

FormClosing shutdown event doesnt write to a file

I have a backup power supply for my computer which is attacted inline with it and the wall. When I pull the power cord from the wall, I have 2-5 minutes before the backup supply shuts down the computer. It is during this time that I want to write data to a file with the code below:



private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason.Equals(CloseReason.WindowsShutDown))
{
writeContents("Interrupted");
sendMessage("PWR - The Spring Test Machine has stopped"); return;

}



if (e.CloseReason.Equals(CloseReason.UserClosing))
{
if (MessageBox.Show("You are closing this application.\n\nAre you sure you wish to exit ?", "Warning: Not Submitted", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Stop) == DialogResult.Yes)
{
writeContents("Interrupted");
return;
}

else
e.Cancel = true;
}

}


The problem is that it didn't work. I dont think the the closing event ever got called. Any ideas would greatly be appreciated. Thank you.





No comments:

Post a Comment