471,825 Members | 1,021 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,825 software developers and data experts.

Windows Service Not Starting

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(ServicesToRu n)
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).BeginIni t()
'
'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
Nov 19 '05 #1
0 2688

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Laszlo Zsolt Nagy | last post: by
2 posts views Thread by Razzie | last post: by
9 posts views Thread by SP | last post: by
1 post views Thread by =?Utf-8?B?cm9zczYxMw==?= | last post: by
5 posts views Thread by eliasen | last post: by
5 posts views Thread by dm3281 | last post: by
4 posts views Thread by =?Utf-8?B?am1hZ2FyYW0=?= | last post: by
reply views Thread by YellowAndGreen | last post: by
aboka
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.