Click here to Skip to main content
15,912,457 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear sir/s,

I am new in windows services, i have been developing new windows services for detecting system date changes.
as soon as system date changes then windows services should write log.

for that i have written following code,
 Protected Overrides Sub OnStart(ByVal args() As String)
   AddHandler SystemEvents.TimeChanged, AddressOf SystemEvents_TimeChanged
End Sub

Private Sub SystemEvents_TimeChanged(ByVal sender As Object, ByVal e As EventArgs)
    WriteToFile("System Time has been changed")
End Sub


But when i change system date then windows service does not fire above event.
Please help me.
Thank you.
Posted

1 solution

Read the remarks on the documentation[^]:

Note
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[^].

The second example on the SystemEvents class[^] explains what you need to do to make this work.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 19-Jan-16 13:22pm    
5ed.
—SA
Sunil Bansode 20-Jan-16 1:56am    
Thanks its working...!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900