Windows Service problems

A

Anil Gupte

I am having a problem getting a service to stay on and I cannot debug it. I
installed it on a computer using installutil.exe In the Services list, it
appears just fine, and I can hit start. However, I get a message saying
"The MediaEncoder Service on Local Computer started and then stopped. Some
services stop if they have nothing to do, for example the Performanace logs
and Alerts service". How can it "have nothing to do"? Mine should do
something! So at least I can then debug it. My code looks like this:

Imports System.ServiceProcess
Imports System.Data.OleDb
Imports WMEncoderLib

#Region " Component Designer generated code "

Public Class MediaEncoderService
Inherits System.ServiceProcess.ServiceBase
Dim WithEvents MediaEncoder As WMEncoder

Protected Overrides Sub OnStart(ByVal args() As String)
MediaEncode()
End Sub

Private Sub MediaEncode()
' My main processing happens here
End Sub
End Class

I even tried putting in a msgbox("Test", OKOnly) in the OnStart event, but
no luck.
So, I can't debug it because it won't even stay started. The install gives
no errors. I am stumped.....
P.S. The onstop event is empty...

Any help appreciated
 
S

ShaneO

Anil said:
I am having a problem getting a service to stay on and I cannot debug it. I
installed it on a computer using installutil.exe In the Services list, it
appears just fine, and I can hit start. However, I get a message saying
"The MediaEncoder Service on Local Computer started and then stopped. Some
services stop if they have nothing to do, for example the Performanace logs
and Alerts service". How can it "have nothing to do"? Mine should do
something!

Having written a couple of Services myself recently, the best advice I
could probably give you is to write a Progressive Log within your main
code. It's quick & dirty, but it might help. (If you don't want to
clutter-up the system log then write-out to a text file).

Private Sub MediaEncode()

Your code here...

LogWrite("1. Processed Code Above!")

More of your code here...

LogWrite("2. Processed More Code!")

..
..
..


End Sub


Private Sub LogWrite(ByVal sMessage As String)

If Not EventLog.SourceExists("MediaEncode") Then
EventLog.CreateEventSource("MediaEncode", "Application")
End If

'Create an EventLog instance and assign its source.
Dim evLogEntry As New EventLog()
evLogEntry.Source = "MediaEncode"

'Write an informational entry to the event log.
evLogEntry.WriteEntry(sMessage, EventLogEntryType.Information)

End Sub


Hope this helps.

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
S

ShaneO

The other point I should have mentioned is, of course, unless you have
some way of re-triggering your "MediaEncode" subroutine then it will
only execute once. (Which is probably more to the point as to why
you're receiving the message that you posted).

Does your code contain a Timer to re-trigger your sub?


ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
A

Anil Gupte

I just got around to this, but I'll tell you this was extremely useful!
Thanx a ton!
 

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

Top