473,382 Members | 1,717 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Windows Service installed but not working???

I managed to get my VB.NET service installed. Now I can't get it to do
anything. Tell me how do you debug smething like this if you have to
manually install the assembly to run it? the same code works just fine in a
VB form but when I initiallize with the WS OnStart event I get nothing. Any
help is greatly appreciated.

TB
Nov 20 '05 #1
6 3424
Are you doing too much work in the OnStart method?

Have you tried debugging your service:
http://msdn.microsoft.com/library/de...owsservice.asp

Specifically:
http://msdn.microsoft.com/library/de...plications.asp

Normally what I do is include a healthy amount of event log messages (via
theServiceBase.EventLog property ) especially in any asynchronous events
that may be raised within the service. Plus I will include Debug.Write &
Trace.Write in strategic locations.

Something like:

Public Class MyService
Inherits System.ServiceProcess.ServiceBase

Private WithEvents Timer1 As System.Timers.Timer

Public Sub New()
MyBase.New()

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

' Add any initialization after the InitializeComponent() call

AddHandler AppDomain.CurrentDomain.UnhandledException, _
AddressOf AppDomain_UnhandledException
End Sub

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.Start()
End Sub

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

Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As
System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
Try
EventLog.WriteEntry("Timer elapsed handler started",
EventLogEntryType.Information)

' Do work here

EventLog.WriteEntry("Timer elapsed handler finished",
EventLogEntryType.Information)
Catch ex As Exception
EventLog.WriteEntry(ex.ToString(), EventLogEntryType.Error)
End Try
End Sub

Private Sub AppDomain_UnhandledException(ByVal sender As Object, _
ByVal e As UnhandledExceptionEventArgs)
EventLog.WriteEntry(e.ExceptionObject.ToString(),
EventLogEntryType.Error)
End Sub
End Class

Note EventLog is inherited from ServiceBase and will be the normal event log
for your service, you can override ServiceBase.EventLog if you want to use a
different Event log.

I configure Debug & Trace to go to a log file.

In your app.config of your Windows Service project:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="myListener" type="System.Diagnostics.TextWriterTraceListener"
initializeData="MyService.log" />
</listeners>
</trace>
</system.diagnostics>
</configuration>
Note the UnhandledException event is not working as I expected in the above,
so I put the Elapsed event in its own Try/Catch.

Hope this helps
Jay
"acool" <no**@sendme.com> wrote in message
news:O1**************@TK2MSFTNGP11.phx.gbl...
I managed to get my VB.NET service installed. Now I can't get it to do
anything. Tell me how do you debug smething like this if you have to
manually install the assembly to run it? the same code works just fine in a VB form but when I initiallize with the WS OnStart event I get nothing. Any help is greatly appreciated.

TB

Nov 20 '05 #2
"acool" <no**@sendme.com> wrote in message
news:O1**************@TK2MSFTNGP11.phx.gbl...
I managed to get my VB.NET service installed. Now I can't get it to do
anything. Tell me how do you debug smething like this if you have to
manually install the assembly to run it?
Start the Service, then atach to the running Process.
the same code works just fine in a VB form but when I initiallize with
the WS OnStart event I get nothing.


Is your Service running beyond the onStart Event? Timer? Closed
loop woith a Sleep() call in it?
Remember that you have to have an application "thread" running for
the Service to /continue/ to work and you get one of those for free
in a Form.

HTH,
Phill W.
Nov 20 '05 #3
I think I am missing soething here is my code:

Imports System.ServiceProcess
Imports System.IO
Imports System.Diagnostics

Protected Overrides Sub OnStart(ByVal args() As String)
' Create a new FileSystemWatcher and set its properties.

Dim watcher As New FileSystemWatcher
watcher.Path = "C:\Temp"
watcher.Filter = "*.xls"

' Add event handlers.
AddHandler watcher.Changed, AddressOf OnChanged
AddHandler watcher.Created, AddressOf OnCreated
AddHandler watcher.Deleted, AddressOf OnChanged
AddHandler watcher.Renamed, AddressOf OnRenamed

' Begin watching.
watcher.EnableRaisingEvents = True

End Sub

' Define the event handlers.
Private Shared Sub OnChanged(ByVal source As Object, ByVal e As
FileSystemEventArgs)
' Specify what is done when a file is changed, created, or deleted.
End Sub

Private Shared Sub OnRenamed(ByVal source As Object, ByVal e As
RenamedEventArgs)
' Specify what is done when a file is renamed.
End Sub

Private Sub OnCreated(ByVal source As Object, ByVal e As
FileSystemEventArgs)
' Specify what is done when a file is created.
File.Create("C:\Temp\OnCreated.txt")
End Sub

So basically when I drop an excel file in my temp folder I want the
OnCreated event to do something. This works fine in a form but not in my
service. I knw I am missing something I just don't know what.



"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:On**************@tk2msftngp13.phx.gbl...
Are you doing too much work in the OnStart method?

Have you tried debugging your service:
http://msdn.microsoft.com/library/de...owsservice.asp
Specifically:
http://msdn.microsoft.com/library/de...plications.asp
Normally what I do is include a healthy amount of event log messages (via
theServiceBase.EventLog property ) especially in any asynchronous events
that may be raised within the service. Plus I will include Debug.Write &
Trace.Write in strategic locations.

Something like:

Public Class MyService
Inherits System.ServiceProcess.ServiceBase

Private WithEvents Timer1 As System.Timers.Timer

Public Sub New()
MyBase.New()

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

' Add any initialization after the InitializeComponent() call

AddHandler AppDomain.CurrentDomain.UnhandledException, _
AddressOf AppDomain_UnhandledException
End Sub

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.Start()
End Sub

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

Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As
System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
Try
EventLog.WriteEntry("Timer elapsed handler started",
EventLogEntryType.Information)

' Do work here

EventLog.WriteEntry("Timer elapsed handler finished",
EventLogEntryType.Information)
Catch ex As Exception
EventLog.WriteEntry(ex.ToString(), EventLogEntryType.Error)
End Try
End Sub

Private Sub AppDomain_UnhandledException(ByVal sender As Object, _
ByVal e As UnhandledExceptionEventArgs)
EventLog.WriteEntry(e.ExceptionObject.ToString(),
EventLogEntryType.Error)
End Sub
End Class

Note EventLog is inherited from ServiceBase and will be the normal event log for your service, you can override ServiceBase.EventLog if you want to use a different Event log.

I configure Debug & Trace to go to a log file.

In your app.config of your Windows Service project:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="MyService.log" />
</listeners>
</trace>
</system.diagnostics>
</configuration>
Note the UnhandledException event is not working as I expected in the above, so I put the Elapsed event in its own Try/Catch.

Hope this helps
Jay
"acool" <no**@sendme.com> wrote in message
news:O1**************@TK2MSFTNGP11.phx.gbl...
I managed to get my VB.NET service installed. Now I can't get it to do
anything. Tell me how do you debug smething like this if you have to
manually install the assembly to run it? the same code works just fine
in a
VB form but when I initiallize with the WS OnStart event I get nothing.

Any
help is greatly appreciated.

TB


Nov 20 '05 #4
Your code by the gives me the following error:
Service cannot be started. System.NullReferenceException: Object reference
not set to an instance of an object.
at WindowsService1.Service1.OnStart(String[] args) in
C:\Dev\WindowsService1\Service1.vb:line 79
at System.ServiceProcess.ServiceBase.ServiceQueuedMai nCallback(Object
state)
It bombs on the
Timer1.Start()

method


"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:On**************@tk2msftngp13.phx.gbl...
Are you doing too much work in the OnStart method?

Have you tried debugging your service:
http://msdn.microsoft.com/library/de...owsservice.asp
Specifically:
http://msdn.microsoft.com/library/de...plications.asp
Normally what I do is include a healthy amount of event log messages (via
theServiceBase.EventLog property ) especially in any asynchronous events
that may be raised within the service. Plus I will include Debug.Write &
Trace.Write in strategic locations.

Something like:

Public Class MyService
Inherits System.ServiceProcess.ServiceBase

Private WithEvents Timer1 As System.Timers.Timer

Public Sub New()
MyBase.New()

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

' Add any initialization after the InitializeComponent() call

AddHandler AppDomain.CurrentDomain.UnhandledException, _
AddressOf AppDomain_UnhandledException
End Sub

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.Start()
End Sub

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

Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As
System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
Try
EventLog.WriteEntry("Timer elapsed handler started",
EventLogEntryType.Information)

' Do work here

EventLog.WriteEntry("Timer elapsed handler finished",
EventLogEntryType.Information)
Catch ex As Exception
EventLog.WriteEntry(ex.ToString(), EventLogEntryType.Error)
End Try
End Sub

Private Sub AppDomain_UnhandledException(ByVal sender As Object, _
ByVal e As UnhandledExceptionEventArgs)
EventLog.WriteEntry(e.ExceptionObject.ToString(),
EventLogEntryType.Error)
End Sub
End Class

Note EventLog is inherited from ServiceBase and will be the normal event log for your service, you can override ServiceBase.EventLog if you want to use a different Event log.

I configure Debug & Trace to go to a log file.

In your app.config of your Windows Service project:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="MyService.log" />
</listeners>
</trace>
</system.diagnostics>
</configuration>
Note the UnhandledException event is not working as I expected in the above, so I put the Elapsed event in its own Try/Catch.

Hope this helps
Jay
"acool" <no**@sendme.com> wrote in message
news:O1**************@TK2MSFTNGP11.phx.gbl...
I managed to get my VB.NET service installed. Now I can't get it to do
anything. Tell me how do you debug smething like this if you have to
manually install the assembly to run it? the same code works just fine
in a
VB form but when I initiallize with the WS OnStart event I get nothing.

Any
help is greatly appreciated.

TB


Nov 20 '05 #5
acool,
You do realize that my code is no where near a complete sample, it is a
partial sample to give you a feel for where to insert EventLog.WriteEntry
statements, to help identify problems.

Hope this helps
Jay

"acool" <no**@sendme.com> wrote in message
news:e0*************@TK2MSFTNGP11.phx.gbl...
Your code by the gives me the following error:
Service cannot be started. System.NullReferenceException: Object reference
not set to an instance of an object.
at WindowsService1.Service1.OnStart(String[] args) in
C:\Dev\WindowsService1\Service1.vb:line 79
at System.ServiceProcess.ServiceBase.ServiceQueuedMai nCallback(Object
state)
It bombs on the
Timer1.Start()

method


"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:On**************@tk2msftngp13.phx.gbl...
Are you doing too much work in the OnStart method?

Have you tried debugging your service:

http://msdn.microsoft.com/library/de...owsservice.asp

Specifically:

http://msdn.microsoft.com/library/de...plications.asp

Normally what I do is include a healthy amount of event log messages (via theServiceBase.EventLog property ) especially in any asynchronous events
that may be raised within the service. Plus I will include Debug.Write &
Trace.Write in strategic locations.

Something like:

Public Class MyService
Inherits System.ServiceProcess.ServiceBase

Private WithEvents Timer1 As System.Timers.Timer

Public Sub New()
MyBase.New()

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

' Add any initialization after the InitializeComponent() call

AddHandler AppDomain.CurrentDomain.UnhandledException, _
AddressOf AppDomain_UnhandledException
End Sub

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.Start()
End Sub

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

Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As
System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
Try
EventLog.WriteEntry("Timer elapsed handler started",
EventLogEntryType.Information)

' Do work here

EventLog.WriteEntry("Timer elapsed handler finished",
EventLogEntryType.Information)
Catch ex As Exception
EventLog.WriteEntry(ex.ToString(), EventLogEntryType.Error)
End Try
End Sub

Private Sub AppDomain_UnhandledException(ByVal sender As Object, _
ByVal e As UnhandledExceptionEventArgs)
EventLog.WriteEntry(e.ExceptionObject.ToString(),
EventLogEntryType.Error)
End Sub
End Class

Note EventLog is inherited from ServiceBase and will be the normal event

log
for your service, you can override ServiceBase.EventLog if you want to use a
different Event log.

I configure Debug & Trace to go to a log file.

In your app.config of your Windows Service project:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="myListener"

type="System.Diagnostics.TextWriterTraceListener"
initializeData="MyService.log" />
</listeners>
</trace>
</system.diagnostics>
</configuration>
Note the UnhandledException event is not working as I expected in the

above,
so I put the Elapsed event in its own Try/Catch.

Hope this helps
Jay
"acool" <no**@sendme.com> wrote in message
news:O1**************@TK2MSFTNGP11.phx.gbl...
I managed to get my VB.NET service installed. Now I can't get it to do
anything. Tell me how do you debug smething like this if you have to
manually install the assembly to run it? the same code works just fine

in
a
VB form but when I initiallize with the WS OnStart event I get

nothing. Any
help is greatly appreciated.

TB



Nov 20 '05 #6
acool,
Did you try putting EventLog.WriteEntry entries in your OnChanged,
OnCreated, OnRenamed methods to see when or if they are being called?
' Define the event handlers.
Private Shared Sub OnChanged(ByVal source As Object, ByVal e As
FileSystemEventArgs)
EventLog.WriteEntry("OnChanged started", _
EventLogEntryType.Information)
' Specify what is done when a file is changed, created, or deleted.

EventLog.WriteEntry("OnChanged ended", _
EventLogEntryType.Information)
End Sub

Are you calling MyBase.OnStart? Did you try putting extra
EventLog.WriteEntry's in your OnStart to make sure it finishes?

Did you use Event Viewer in Control Panel - Admistrative Tools to see your
events that are written above?

Alternatively did you try Trace.Write or Debug.Write and the app.config to
write to a log file to see what is happening?

Did you attempt to debug your app (start it, put break points in OnChanged,
OnCreated, OnRenamed methods) to see what happens?

Hope this helps
Jay

"acool" <no**@sendme.com> wrote in message
news:eE**************@TK2MSFTNGP09.phx.gbl... I think I am missing soething here is my code:

Imports System.ServiceProcess
Imports System.IO
Imports System.Diagnostics

Protected Overrides Sub OnStart(ByVal args() As String)
' Create a new FileSystemWatcher and set its properties.

Dim watcher As New FileSystemWatcher
watcher.Path = "C:\Temp"
watcher.Filter = "*.xls"

' Add event handlers.
AddHandler watcher.Changed, AddressOf OnChanged
AddHandler watcher.Created, AddressOf OnCreated
AddHandler watcher.Deleted, AddressOf OnChanged
AddHandler watcher.Renamed, AddressOf OnRenamed

' Begin watching.
watcher.EnableRaisingEvents = True

End Sub

' Define the event handlers.
Private Shared Sub OnChanged(ByVal source As Object, ByVal e As
FileSystemEventArgs)
' Specify what is done when a file is changed, created, or deleted. End Sub

Private Shared Sub OnRenamed(ByVal source As Object, ByVal e As
RenamedEventArgs)
' Specify what is done when a file is renamed.
End Sub

Private Sub OnCreated(ByVal source As Object, ByVal e As
FileSystemEventArgs)
' Specify what is done when a file is created.
File.Create("C:\Temp\OnCreated.txt")
End Sub

So basically when I drop an excel file in my temp folder I want the
OnCreated event to do something. This works fine in a form but not in my
service. I knw I am missing something I just don't know what.



"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:On**************@tk2msftngp13.phx.gbl...
Are you doing too much work in the OnStart method?

Have you tried debugging your service:

http://msdn.microsoft.com/library/de...owsservice.asp

Specifically:

http://msdn.microsoft.com/library/de...plications.asp

Normally what I do is include a healthy amount of event log messages (via theServiceBase.EventLog property ) especially in any asynchronous events
that may be raised within the service. Plus I will include Debug.Write &
Trace.Write in strategic locations.

Something like:

Public Class MyService
Inherits System.ServiceProcess.ServiceBase

Private WithEvents Timer1 As System.Timers.Timer

Public Sub New()
MyBase.New()

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

' Add any initialization after the InitializeComponent() call

AddHandler AppDomain.CurrentDomain.UnhandledException, _
AddressOf AppDomain_UnhandledException
End Sub

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.Start()
End Sub

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

Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As
System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
Try
EventLog.WriteEntry("Timer elapsed handler started",
EventLogEntryType.Information)

' Do work here

EventLog.WriteEntry("Timer elapsed handler finished",
EventLogEntryType.Information)
Catch ex As Exception
EventLog.WriteEntry(ex.ToString(), EventLogEntryType.Error)
End Try
End Sub

Private Sub AppDomain_UnhandledException(ByVal sender As Object, _
ByVal e As UnhandledExceptionEventArgs)
EventLog.WriteEntry(e.ExceptionObject.ToString(),
EventLogEntryType.Error)
End Sub
End Class

Note EventLog is inherited from ServiceBase and will be the normal event

log
for your service, you can override ServiceBase.EventLog if you want to use a
different Event log.

I configure Debug & Trace to go to a log file.

In your app.config of your Windows Service project:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="myListener"

type="System.Diagnostics.TextWriterTraceListener"
initializeData="MyService.log" />
</listeners>
</trace>
</system.diagnostics>
</configuration>
Note the UnhandledException event is not working as I expected in the

above,
so I put the Elapsed event in its own Try/Catch.

Hope this helps
Jay
"acool" <no**@sendme.com> wrote in message
news:O1**************@TK2MSFTNGP11.phx.gbl...
I managed to get my VB.NET service installed. Now I can't get it to do
anything. Tell me how do you debug smething like this if you have to
manually install the assembly to run it? the same code works just fine

in
a
VB form but when I initiallize with the WS OnStart event I get

nothing. Any
help is greatly appreciated.

TB



Nov 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Michael Adkins | last post by:
I have a new ASP project that I need to desperately test on my Windows 2000 machine before posing to my Hosting Company. I am having problems getting the ASP pages to run from LocalHost. I will...
2
by: Dermot O'Loughlin | last post by:
I am trying to install a dotnet application using it's websetup msi dotnet application. I am getting the following error: The Windows Installer Service could not be accessed. This can occur if...
0
by: Vipul Patel | last post by:
Hi, There is a project requirement to create an installer for a windows service created in VC++ 7.0 unmanaged code. Can any one guide to a link or working sample as to where I can get the...
5
by: Andrea Vincenzi | last post by:
Help me please, I'm totally stuck! My Visual Studio 2003 debugger stopped working after I installed Windows XP Service Pack 2. Here is what happens (with any project, even a "Hello, world"...
4
by: tshad | last post by:
What would be a good way to check programmatically whether a service was running? We have a service that dies periodically and I need to check to see if this service is running. I know how to...
3
by: Vikas Kumar | last post by:
I have created a windows service that service downloads updated database after regular intervals till now i am setting path in app.config where it will download database and will use it from that...
15
by: =?Utf-8?B?TVNU?= | last post by:
To demonstrate my problem, I have a very simple VB Windows application. It has a text box that is used to display a counter, a button to reset the counter, and a timer that increments the counter...
1
by: eblackmo | last post by:
I have a test network consisting of four servers running windows 2003 server R2 SP2. I have set up a domain which functioned correctly for about a day and a half until the other servers decided they...
5
by: dm3281 | last post by:
I'm really starting to hate writing services -- or trying to, anyway. Why do I need to rename my project to the service name? Why do I need to set the "ServiceName" property to my service name?...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.