Windows Service Not Starting

T

tshad

I have a Windows Service I created that just sets a timer and writes to
EventLog every 10 seconds.

It installed fine and it actually starts. But it says it doesn't. The
progress bar shows the progress fine until it hits about halfway. It then
stops there for about 4 or 5 seconds then goes a little farther. I then get
a message:

Could not start the MyService Service on Local Computer.
Error 1053: The service did not respond to the Start or control request in a
timely fashion.

I look at the MyService log from Event Viewer and it is running and writing
to the Event log every 10 seconds, as it should.

But in the Services screen, it shows MyService as starting (not started) and
I can't stop it

If I try to stop it from Task Manager, I get the message:

The operation could not be completed.
Access is denied.

I have to reboot to stop it.

Here is the code:

****************************************************************************
*****
Imports System.ServiceProcess

Public Class Service1
Inherits System.ServiceProcess.ServiceBase

#Region " Component Designer generated code "

Public Sub New()
MyBase.New()

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

' Add any initialization after the InitializeComponent() call

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
Service1}

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.
Friend WithEvents Timer1 As System.Timers.Timer
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.Timer1 = New System.Timers.Timer()
CType(Me.Timer1,
System.ComponentModel.ISupportInitialize).BeginInit()
'
'Timer1
'
Me.Timer1.Enabled = True
Me.Timer1.Interval = 10000
'
'Service1
'
Me.ServiceName = "Service1"
CType(Me.Timer1, System.ComponentModel.ISupportInitialize).EndInit()

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.
Timer1.Enabled = True
End Sub

Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your
service.
Timer1.Enabled = False
End Sub

Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As
System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
Dim MyLog As New EventLog()

' Check if the Event Log exists
If Not MyLog.SourceExists("MyService") Then
MyLog.CreateEventSource("MyService", "Myservice Log") ' Create
Log
End If
MyLog.Source = "MyService"
' Write to the Log
MyLog.WriteEntry("MyService Log", "This is log on " &
CStr(TimeOfDay), EventLogEntryType.Information)
End Sub
End Class
****************************************************************************
*****

Why isn't it working correctly?

This program isn't doing much and it seems to be working fine, except for
the starting/stopping parts.

Thanks,

Tom
 
Joined
Jan 2, 2008
Messages
1
Reaction score
0
I've got the same problem

I'm having a similar problem with my windows service. I think it is something to do with the size of the event log. If I clear down the Application log, the service starts fine.
I'm trying to do some error trapping so writing to the Event log if it is full, doesn't cause the Service start to jam on "Starting"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top