Reputation: 124
static void Main()
{
// Set the SystemEvents class to receive event notification when a user
// when display settings change.
SystemEvents.DisplaySettingsChanged += new
EventHandler(SystemEvents_DisplaySettingsChanged);
// For demonstration purposes, this application sits idle waiting for events.
Console.WriteLine("This application is waiting for system events.");
Console.WriteLine("Press <Enter> to terminate this application.");
Console.ReadLine();
}
private void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e)
{
Console.WriteLine("Display setting change .");
}
i have created a windows service.when i restart the system and login then change the display setting it will not work and event is not fire but the service is runing.
when i restart the service then i change the display setting then display setting event fire.
i think SystemEvents.DisplaySettingsChanged may depend on some service.
Upvotes: 0
Views: 1623
Reputation: 13940
The SystemEvents class uses the WTSSession APIs under the covers, which rely on the Terminal Services service (TermService). If your service messes with SystemEvents before that service is started, it will fail in interesting ways. If you make your service depend on TermService, the SystemEvents init should work by the time your service starts.
Upvotes: 1