You should put in a try/catch to see if an error is happening. If so, write the message to the Windows event log. This is a good practice for services anyway.
>I think the issue is related to the Windows Service does not wait for the timer. For example, if I execute it from the EXE, I can see a message box at the end showing a message that tells me that the OnStop() event was reached. So, while the message is showing, I can see the executable in the Task manager. Then, I click ok and the OnStop() finishes making the executable to complete and it goes out of the Task manager.
>
>So, from the Services interface or from the sc command, I believe for the windows service to properly run, it has to fall into the wait step for the timer to kick in. But, this does not seem to happen as, even if the timer is activated at the end of the OnStart() event, it falls right away in the OnStop() event making the executable to disappear from the memory. This is what I can see from the Task manager.
>
>My Main class is like this:
>
>
>Public Class Main
> Inherits WindowsService
>
> Shared Sub Main(ByVal toArgs As String())
> Startup(toArgs, New Main(), True)
> End Sub
>
>
>And, the base class:
>
>
>Imports System.ServiceProcess
>
>Public Class WindowsService
> Inherits ServiceBase
>
> Public oTimer As New System.Timers.Timer(5000)
>
> Protected Shared Sub Startup(toArgs As String(), toWindowsService As WindowsService, tlInteractiveWait As Boolean)
> toWindowsService.OnStart(toArgs)
> End Sub
>
> Protected Overrides Sub OnStart(ByVal toArgs As String())
> MyBase.OnStart(toArgs)
>
> ' Define the timer
> AddHandler oTimer.Elapsed, AddressOf ServiceTimer
>
> ' Start the timer
> oTimer.Enabled = True
>
> System.Windows.Forms.MessageBox.Show("End")
> End Sub
>
> Protected Overrides Sub OnStop()
> MyBase.OnStop()
> End Sub
>
> Private Sub ServiceTimer(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs)
> End Sub
>
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer