Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Service Program Starts and then Stops?

Posted on 2003-12-04
4
Medium Priority
?
725 Views
Last Modified: 2007-12-19
I have a simple Service program that compiles and installs OK.  It Shows up in services but it's not started.  I select start and the following message appears:

The service on Local computer started and then stopped.  Some services stop automatically if the have no work to do, for example the Performance Logs and Alerts service.

Heres the code.  It's pretty bare bones.

thx

Public Sub New()
        MyBase.New()

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

        ' Add any initialization after the InitializeComponent() call
        CanStop = True
        CanPauseAndContinue = True
        ServiceName = "Archive Backup Service"
        timer = New Timer
        timer.Interval = 1
        AddHandler timer.Elapsed, AddressOf OnTimer

    End Sub

    'UserService overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    ' The main entry point for the process
    <MTAThread()> _
    Shared Sub Main()
        Dim ServicesToRun() As System.ServiceProcess.ServiceBase

        ' More than one NT Service may run within the same process. To add
        ' another service to this process, change the following line to
        ' create a second service object. For example,
        '
        '   ServicesToRun = New System.ServiceProcess.ServiceBase () {New Service1, New MySecondUserService}
        '
        ServicesToRun = New System.ServiceProcess.ServiceBase() {New ArcBack}

        System.ServiceProcess.ServiceBase.Run(ServicesToRun)
    End Sub

    'Required by the Component Designer
    Private components As System.ComponentModel.IContainer

    ' NOTE: The following procedure is required by the Component Designer
    ' It can be modified using the Component Designer.  
    ' Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        '
        'ArcBack
        '

    End Sub

#End Region

    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.
        EventLog.WriteEntry("Archive Backup Started")
        timer.Enabled = True
    End Sub

    Protected Overrides Sub OnStop()
        ' Add code here to perform any tear-down necessary to stop your service.
        EventLog.WriteEntry("Archive Backup Stopped")
        timer.Enabled = False

    End Sub
    Protected Overrides Sub OnPause()
        EventLog.WriteEntry("Archive Backup Paused")
        timer.Enabled() = False
    End Sub

    Protected Overrides Sub OnContinue()
        EventLog.WriteEntry("Archive Backup Continuing")
        timer.Enabled = True
    End Sub

    Protected Sub OnTimer(ByVal source As Object, ByVal e As ElapsedEventArgs)
        EventLog.WriteEntry("The timer fired!")
    End Sub

End Class
0
Comment
Question by:skaaman
[X]
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
4 Comments
 
LVL 12

Assisted Solution

by:roverm
roverm earned 375 total points
ID: 9876374
Try placing a 'normal' timer on your form.
Then catch that event. Maybe there's something wrong with the system.timer class. (tho I don't know what ;-) )

D'Mzz!
RoverM
0
 
LVL 3

Accepted Solution

by:
TwoSide earned 375 total points
ID: 9876378
Thats easy, you have to start your timer because without that the timer doesn't do nothing that's why you got this error!!!

    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.
        EventLog.WriteEntry("Archive Backup Started")
        timer.Enabled = True
        timer.start
    End Sub
0
 

Author Comment

by:skaaman
ID: 9877238
Both good suggestions but neither resolved the issue.  I've rewarded you both points based on constructive input

The solution was a Log On configuration issue.  I was playing around with the properties and under the  Log On tab,   Log in as:, This Account was selected with a default server and password in place.  I changed Log in as to Local System Account and the problem was resolved.  I'll have to poke around to see If I can set this on install.

thx

Kurt
0
 

Expert Comment

by:baeaton
ID: 10127601
I also found that this error will occur if you screw up your app.config file.  I had my service working fine.  Then, I went into make some changes to the app.config.  Added a new key that had a bad character in the value "<"  tisk... tisk...

It'll compile just fine but the the app.config becomes invalid and that'll stop the whole thing from working.  The only reason I found it was I noticed a little warning in the task list about the invalid character.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

721 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