views:

108

answers:

1

I have a windows service written in C# with .Net 3.5. It had been running on a server for a few weeks when it was discovered the that the server's timezone was not set correctly. This was corrected but the service was not restarted. To my surprise the service did not pick up the clock change.

My question is will this also be a problem during daylight savings time switches? And if so, what can be done about it besides restarting the service?

+1  A: 

I would have said add a handler for the the Microsoft.Win32.SystemEvents.TimeChanged event. However, it doesn't work directly in a Service:

This event is only raised if the message pump is running. In a Windows service, unless a hidden form is used or the message pump has been started manually, this event will not be raised. For a code example that shows how to handle system events by using a hidden form in a Windows service, see the SystemEvents class.

You need to look at Example2 on this second page:

Example 2

The following code example demonstrates a very simple Windows service that handles the TimeChanged and UserPreferenceChanged events. The example includes a service named SimpleService, a form named HiddenForm, and an installer. The form provides the message loop that is required by system events.

ChrisF