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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

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.  
Major Serverless Shift

Comparison of major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform


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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

777 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