1

I am looking for how i can build a service that is aware when the system clock is adjusted in windows e.g. by getting some notification when w32time performs a synchronisation to time.windows.com

To give some context, I have an service that I recently converted to a service that collects information throughout the day, and in case of a crash, it uses the system clock to recover the state accumulated throughout the day.

Recently I diagnosed a problem with the service and state recovery and what i whitnessed was that the moment my service is launched it reports a wrong date- my working theory is that my service is effectively started before the system clock has been adjusted.

So what I would like to do is reinitialize the state when I detect that the system clock has been synchronized where effectivly the day has been changed. I am aware that there is SystemEvents.TimeChanged but from what I can gather from MSDN this event only reports user-initiated events and may not work for regular system clock synchroniation.

This brings me to the point where I'm looking for an alternatives ways of detecting when the system clock has been adjusted.

Lawrence Kok
  • 1,568
  • 11
  • 29
  • _"my working theory is that my service is effectively started before the system clock has been adjusted."_ - What was the scenario where this happened? It's not like the system clock is some value on each start, and then gets corrected. – ProgrammingLlama Nov 12 '20 at 03:39
  • Well basically, once I start the application/service, I record DateTime.now in an log. This morning it was reporting date of 11th nov instead of 12th nov. When I logged in (remotely) to service the datetime has already been corrected to the 12th. The system is configured to sync with `time.windows.com`. So if nobody (read me) manually corrects the date, the system must have automatically corrected it. The Windows Time service (w32tm) seems like the most plausible explanation. – Lawrence Kok Nov 12 '20 at 05:01
  • It seems like an unusual occurrence though. As per [this question/answer](https://stackoverflow.com/a/7852300/3181933) are there logs to indicate the time was updated? – ProgrammingLlama Nov 12 '20 at 05:05
  • 1
    Most likely you are seeing the same timestamp, just in different timezones. – Jeremy Lakeman Nov 12 '20 at 05:31
  • @john there are events like that logged. Upon investigation, I see three events that are likely, the cause. First I see the computer going into sleep mode (kernel power), and consecutively revived from sleep mode, following a time update (kernel general). It looks like instead of a shutdown, the computer has placed the system into sleep mode. – Lawrence Kok Nov 12 '20 at 05:52

0 Answers0