Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Debugging a Win Service app: no reaction

Status
Not open for further replies.

IlyaRabyy

Programmer
Nov 9, 2010
568
US
Colleagues,
I'm trying to test and debug a Windows Service program.
The Program is supposed to report files creation/modification/deletion of XML files by writing a report line to a LOG file.
(If it's of any significance, that same program made as WinForms actually works. I copy-pasted the relevant parts - OnFileChanged(), etc. - from that WinForms app to the WinService app.)

To test and debug my WinService app, I followed the instructions on this page to the letter:
- Created program, made an EXE (in the \bin\Debug subdir),
- Installed it as a Service,
- Started service,
- In the VS IDE (run as Admin), attached it to the service,
- Did what this service is supposed to report (deleted one XML in the monitored directory) - no reaction!
- I stopped and [re]started my service (several times) - zilch/nada/bubkis/[curse] (don't wanna slip to profanities... )
Moreover, even program's performance LOG file was not created!
I've been struggling to find out the cause of this behavior for 3 workdays now - no success. [banghead]

Here's the code of the main class:
Code:
'====================================================================================================================================
Public Class FileMonitorService
'====================================================================================================================================
Inherits ServiceBase
Public CommonSubs As CommonSubs
Public fsWatch As FileSystemWatcher
Public gsWorkDir As String = ""
Public gaWorkSubDirs() As String
Public gsStartDir = CommonSubs.AddBackSlash((Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)).Replace("\bin\Debug", "\"))
Public gsAppName = (System.Reflection.Assembly.GetExecutingAssembly().GetName().Name).ToUpper()
Public gsLogFile = gsStartDir + gsAppName + ".LOG"

Here's the code in the OnStart() proc:
Code:
'====================================================================================================================================
Protected Overrides Sub OnStart(ByVal args() As String)
'====================================================================================================================================
' Start or continue the LOG file
Dim lsLogStr As String = CommonSubs.Replicate("=", 80) + vbCrLf + String.Format(Now, "yyyy-MM-dd HH:mm:ss") + _
			": Service started" + vbCrLf + CommonSubs.Replicate("=", 80) + vbCrLf
CommonSubs.Write2LogFile(gsLogFile, lsLogStr)

As I've already said, this LOG file is not being created. And the questions are:
1. Is the OnStart() the right place for creating this LOG file?

If not, then

2. Where, in my program, am I to place the code for creation of this LOG file?

TIA!

Regards,

Ilya
 
I rather suspect that you've not wired up the service properly. Difficult to tell, though, from the code you have posted. But there's no sign of you actually intialising the FileWatcher, for example
 
StrongM said:
there's no sign of you actually initializing the FileWatcher, for example

Code:
'====================================================================================================================================
Public Sub Main(args As String())
'====================================================================================================================================
....
Dim servicesToRun() As ServiceBase
servicesToRun = New ServiceBase() {New FileMonitorService()}
ServiceBase.Run(servicesToRun)

This should start the Service, right?
Or - I'm missing something?

Regards,

Ilya
 
I think you need to go and read the documentation about how to write a Windows service in VB.NET very carefully.

To summarise ..
>This should start the Service, right?
Nope, it just starts the internal plumbing that supports your service

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top