
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Dealing with Operating System Shutdown, Power Management, or User Session Changes
|
1087
Discussion
The .NET Framework provides many opportunities to get feedback from the system
when there are changes due to either user or system interactions. The
SystemEvents
class exposes more events than just the ones used in this recipe. For a full listing, see
Table 20-1.
Keep in mind that these are system events. Therefore, the amount of
work done in the handlers should be kept to a minimum so the sys-
tem can move on to the next task.
break;
}
}
private static void OnSessionEnded(object sender, SessionEndedEventArgs e)
{
switch (e.Reason)
{
case SessionEndReasons.Logoff:
Debug.WriteLine("Session ended as the user is logging off");
break;
case SessionEndReasons.SystemShutdown:
Debug.WriteLine("Session ended as the OS is shutting down");
break;
}
}
Table 20-1. The SystemEvents events
Value Description
DisplaySettingsChanged User changed display settings.
DisplaySettingsChanging Display settings are changing.
EventsThreadShutdown Thread listening for system events is terminating.
InstalledFontsChanged User added or removed fonts.
PaletteChanged User switched to an application with a different palette.
PowerModeChanged User suspended or resumed the system.
SessionEnded User shut down the system or logged ...