VB.Net Service won't write to Event Log

Posted on 2003-03-21
Medium Priority
Last Modified: 2012-08-14
I have written a small test service in visual basic .net.  I can install the service using installutil and I can start and stop it successfully.  Here is the problem.  I have a Timer on the service that fires every 10 seconds and writes to the event log.  I never see any of the timer events in the log.  I see the “timer started” message and the “timer stopped” message but it seems as if none of the timer1_tick events ever happen.  Here is the code:

    Protected Overrides Sub OnStart(ByVal args() As String)
        Timer1.Enabled = True
        writeLogEvent("AMS StartedTimer", EventLogEntryType.Information)
    End Sub

    Protected Overrides Sub OnStop()
        Timer1.Enabled = False
        writeLogEvent("AMS StopedTimer", EventLogEntryType.Information)
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) _
                            Handles Timer1.Tick
        writeLogEvent("This is a Test", EventLogEntryType.Information)
    End Sub

    Private Sub writeLogEvent(ByVal Message As String, ByVal EntryType As EventLogEntryType)
        Dim MyLog As New EventLog()
        If Not MyLog.SourceExists("AMS") Then
            MyLog.CreateEventSource("AMS", "AMS Log")
        End If

        MyLog.Source = "AMS"
        MyLog.WriteEntry("AMS Log", Message, EntryType)

    End Sub

AS I said the StartedTimer and Stopped Timer events make it to the log so I know my writelog function works, but timer1_tick never fires.
Question by:USBSnowCrash

Expert Comment

ID: 8183252
The web service runs almost like an asp page.  You call the service.  The Web service is run.  The response is created and the web service ends.  That means that unless creating the response takes longer than 10 seconds, the timer event wont be called.  What exactly, are you trying to achive.  It seems that you are tring to initiate a comunication from the server to the client.

Author Comment

ID: 8183303

     Sorry if I was unclear but this is a windows service i.e. an NT Service.  This is not a Web Service.  this is they type of service that shows up in the control panel under "Services".

Expert Comment

ID: 8183487
Sorry my mistake.  I dont think that I can help you much.  
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.


Expert Comment

ID: 8186301
Please check it once again by deleting the service and reboot ur machine and check. I tested the same on my windows 2000  machine where i am able to see all the messages correctly.. No problem with ur code..

Accepted Solution

vrubba earned 500 total points
ID: 8197528
Had the exact same problem.  Been fiddling with it all day... ended up recreating the same app over and over with the same problem as you.  the timer control just won't fire.

then i noticed that there are TWO timer controls... one under the COMPONENTS tab and one under the WINDOWS FORMS tab.  i had mistakenly, without really looking, dragged the one from the WINDOWS FORMS tab.

Once I realized what I had done, i deleted that one and dragged the one from the COMPONENTS tab.  Problem solved.

Author Comment

ID: 8225611
Good Call vrubba!!! That was exactlly what I had done wrong.

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question