Re: Windows Service installed but not working???

From: Jay B. Harlow [MVP - Outlook] (Jay_Harlow_MVP_at_msn.com)
Date: 05/18/04


Date: Tue, 18 May 2004 08:46:08 -0500

Are you doing too much work in the OnStart method?

Have you tried debugging your service:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsdebug/html/vxtskdebugginwindowsservice.asp

Specifically:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskdebuggingserviceapplications.asp

Normally what I do is include a healthy amount of event log messages (via
theServiceBase.EventLog property ) 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.ServiceProcess.ServiceBase

    Private WithEvents Timer1 As System.Timers.Timer

    Public Sub New()
        MyBase.New()

        ' This call is required by the Component Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call

        AddHandler AppDomain.CurrentDomain.UnhandledException, _
            AddressOf AppDomain_UnhandledException
    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.ElapsedEventArgs) Handles Timer1.Elapsed
        Try
            EventLog.WriteEntry("Timer elapsed handler started",
EventLogEntryType.Information)

            ' Do work here

            EventLog.WriteEntry("Timer elapsed handler finished",
EventLogEntryType.Information)
        Catch ex As Exception
            EventLog.WriteEntry(ex.ToString(), EventLogEntryType.Error)
        End Try
    End Sub

    Private Sub AppDomain_UnhandledException(ByVal sender As Object, _
            ByVal e As UnhandledExceptionEventArgs)
        EventLog.WriteEntry(e.ExceptionObject.ToString(),
EventLogEntryType.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.EventLog 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" ?>
<configuration>
 <system.diagnostics>
  <trace autoflush="true" indentsize="4">
   <listeners>
    <add name="myListener" type="System.Diagnostics.TextWriterTraceListener"
initializeData="MyService.log" />
   </listeners>
  </trace>
 </system.diagnostics>
</configuration>

Note the UnhandledException 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

"acool" <none@sendme.com> wrote in message
news:O1uDD1NPEHA.2452@TK2MSFTNGP11.phx.gbl...
> I managed to get my VB.NET service installed. Now I can't get it to do
> anything. Tell me how do you debug smething like this if you have to
> manually install the assembly to run it? the same code works just fine in
a
> VB form but when I initiallize with the WS OnStart event I get nothing.
Any
> help is greatly appreciated.
>
>
>
> TB
>
>



Relevant Pages

  • Re: Windows Service Remoting Question
    ... Why you don't see anything in the event log I'm ... >> Sub Main ... >> service server. ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: Max number of items in a listbox?
    ... >> ListBox as sort of an event log. ... >> limiting the number of entries that can accumulate in this listbox ... >Sub AddLogEntry ...
    (microsoft.public.vb.general.discussion)
  • Write log description
    ... Private Sub Page_Load(ByVal sender As System.Object, ... Sub WriteToEventLog(ByVal LogName As String, ... 'Create event log if it doesn't exist ...
    (microsoft.public.dotnet.general)
  • Re: Windows Services
    ... Public Class MyService ... End Sub ... Note EventLog is inherited from ServiceBase and will be the normal event log ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Windows Service - Event Log
    ... It has got nothing to do with Event log and permissions. ... Check your Onstart Method. ... Have a timer on your service design page and ...
    (microsoft.public.dotnet.languages.csharp)