I want to catch the PowerModeChanged event before the computer or notebook is suspended.
My code snippet is the following:
void SystemEvents_OnPowerChanged(object sender, PowerModeChangedEventArgs e)
{
string fileName = DateTime.Today.ToString("yyyy-MM-dd") + ".txt"; //Den aktuellen Tag ermittlen
string time = DateTime.Now.ToString("HH:mm:ss"); //Die Zeit beim Eintreten des Events ermitteln
switch (e.Mode) //Event abfangen
{
case PowerModes.Resume: //Das Betriebssystem steht unmittelbar davor, aus dem Ruhezustand fortgesetzt zu werden, ...
LogToFile(fileName, " - " + time + " -> Pause."); //... sodass die Pause beendet ist.
lblStatus.Text = "Arbeit, Arbeit! :)";
break;
case PowerModes.Suspend: //Die Ausführung des Betriebssystems wird unterbrochen, ...
LogToFile(fileName, "\n" + time); //... sodass die Pause beginnt, also wird ein Zeilenumbruch hinzugefügt.
lblStatus.Text = "Luft filtern. :|";
break;
}
}
If the standby is finished the event is fired two times. First e.Mode is equal to Suspend and at the second time e.Mode is equal Resume.
How can I pause the Standby-Mode and save the string to the file? Why is the event fired twice after the Standby, although it should fired once before and once after?