
MyBase.OnSessionChange(changeDescription)ĭim numb As String = "#,#,#,#,#" Protected Overrides Sub OnSessionChange(changeDescription As ) Protected Overrides Sub OnCustomCommand(command As Integer)
493400 idle timer code#
' Add code here to perform any tear-down necessary to stop your service. ' in motion so your service can do its work. Protected Overrides Sub OnStart(ByVal args() As String) While putting together the following example, I realized I had forgotten the OnSessionChange method which would let your service know when a user logged on or off - not everything you wanted to know, but might be useful.
493400 idle timer windows#
You just add a field to your service, then override the OnCustomCommand method to capture the value passed from the ServiceController component in your Windows Forms desktop application. Reed Kimble - "When you do things right, people won't be sure you've done anything at all" I agree with Riquel that at this point we would need to know more about what work the service performs before much more could be suggested. Kick off an extensive process that might disrupt the user. However, you could still have a separate desktop application designed to control the service and it could If the program is going to perform work that will be known to be disruptive to the user, then it probably should not be created as a service. Services and the user environment already. So why should the service be concerned with whether the user is active or idle? Windows does a good job of balancing the processing time between the running Services are designed to do their work in the background with or without an active user. There are ways to do it as I mentioned, but the question is if there is a reason to do it. A service automatically starts whenever the computer is turned on. I just want it to run in the background whenever the user starts the computer. I wanted it to be a service because i don't want the user to have to start the program. Thanks Reed - so it might can't be done then? It always creates it 10 minutes after the service has started NOT 10 minutes after inactivity. Return (Environment.TickCount - lastInput.dwTime) / 1000īasically, if it is afer 8:00 AM and 10 minutes have passed without inactivity, create the text file. LastInput.cbSize = Marshal.SizeOf(lastInput) Public ReadOnly Property IdleTime() As Integer (ByRef lastInput As LASTINPUTINFO) As Boolean Private Declare Function GetLastInputInfo Lib "User32.dll" _ System.IO.File.Create("C:\j\t" & it.IdleTime.ToString & ".txt") System.IO.File.Create("C:\j\s" & it.IdleTime.ToString & ".txt") '''' System.IO.File.AppendAllText("\\ed381bob2\Management\DB\Logs\Energy Saver\" & Format(Today.Date, "yyyy/MM/dd").Replace("/", "_") & ".csv", & ", " & My.Computer.Name & ", X" & vbNewLine) Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As ) Handles Timer1.Elapsed Thanks Joel! However it didn't seem to work.
