Eric,
Are you doing too much work in the OnStart method?
Have you tried debugging your service:
http://msdn.microsoft.com/library/de...owsservice.asp
Normally what I do is include a healthy amount of event log messages (via
..EventLog) especially in any asynchronous events that may be raised within
the service. Plus I will include Debug.Write & Trace.Write in strategic
locations.
Something like:
Public Class MyService
Inherits System.ServiceP rocess.ServiceB ase
Private WithEvents Timer1 As System.Timers.T imer
Public Sub New()
MyBase.New()
' This call is required by the Component Designer.
InitializeCompo nent()
' Add any initialization after the InitializeCompo nent() call
AddHandler AppDomain.Curre ntDomain.Unhand ledException, _
AddressOf AppDomain_Unhan dledException
End Sub
Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set things
' in motion so your service can do its work.
Timer1.Start()
End Sub
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your
service.
Timer1.Stop()
End Sub
Private Sub Timer1_Elapsed( ByVal sender As System.Object, ByVal e As
System.Timers.E lapsedEventArgs ) Handles Timer1.Elapsed
Try
EventLog.WriteE ntry("Timer elapsed handler started",
EventLogEntryTy pe.Information)
' Do work here
EventLog.WriteE ntry("Timer elapsed handler finished",
EventLogEntryTy pe.Information)
Catch ex As Exception
EventLog.WriteE ntry(ex.ToStrin g(), EventLogEntryTy pe.Error)
End Try
End Sub
Private Sub AppDomain_Unhan dledException(B yVal sender As Object, _
ByVal e As UnhandledExcept ionEventArgs)
EventLog.WriteE ntry(e.Exceptio nObject.ToStrin g(),
EventLogEntryTy pe.Error)
End Sub
End Class
Note EventLog is inherited from ServiceBase and will be the normal event log
for your service, you can override ServiceBase.Eve ntLog if you want to use a
different Event log.
I configure Debug & Trace to go to a log file.
In your app.config of your Windows Service project:
<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<system.diagnos tics>
<trace autoflush="true " indentsize="4">
<listeners>
<add name="myListene r" type="System.Di agnostics.TextW riterTraceListe ner"
initializeData= "MyService. log" />
</listeners>
</trace>
</system.diagnost ics>
</configuration>
Note the UnhandledExcept ion event is not working as I expected in the above,
so I put the Elapsed event in its own Try/Catch.
Hope this helps
Jay
"Eric" <an*******@disc ussions.microso ft.com> wrote in message
news:2A******** *************** ***********@mic rosoft.com...
Hi,
I built a service that watch file in a directory. I use a simple
filewatcher and add a handler to do something when a file is created. I have
the following problem. I can build it, I can install it, I can start it but
when I start it I have a message that the service is stop because it does
nothing and it doesn't execute the code in the service. Please if you have
any idea it will be appreciate.
Thanks you