windows service
Hi!
I'm creating a windows service where i want to execute an exe whenever the service is started.
I tried process.start("myexe") in the On_Start() event of the windows
service... but the service starts and stops as soon as it is started
saying that the service has no work to do.

please help!!!
[375 byte] By [
MariamCR] at [2007-12-23]
Hi Brendan Grant!
Thanks for your response, I'd appreciate it very much cause this is my first time building a service in .Net...
What I'm trying to do it's to execute a code (private function iniciar () ) which is in the service, then I also create a Setup Project in order to install and keep run the service on a server.
Actually my code look like this:
' -
Protected Overrides Sub OnStart(ByVal args() As String)
Timer1.Enabled = Trueiniciar()aTimer =
New System.Timers.TimerAddHandler aTimer.Elapsed, AddressOf OnTimer' por default --> aTimer.AutoReset(True)' intervalo dado en segundos aTimer.Interval = 900000
' => pb! cada 15 min (5000 = 5 seg)' dispara accionaTimer.Enabled =
TrueEnd Sub
' -
Protected Overrides Sub OnStop()aTimer.Enabled = FalseEnd Sub' -
Private
Sub iniciar()....End Sub' -
Private
Sub aTimer_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles aTimer.Elapsediniciar()
End Sub While you've got an AddHandler statement to link the aTimer.Elapsed event to something... you don't appear to have an OnTimer() method within your code... you might want to change that call to aTimerElapsed.
Also... running a System.Timers.Timer is a Windows service isn't always the best idea... instead try using System.Threading.Timer instead which tends to be a little more reliable in this context.
Hi!
I've resolve the problem about the system starting... now my service is running... but there's a problem with the --System.Timers.Timer --that I am using, It works perfect the first time but the Thread doesn't works again.
Could be possible the OnTimer method is correctly running only the fist time?
I also tryed using a --System.Threading.Timer -- but it's not working even by the first time.
-
These is a piece of how my code looks like:
Protected
Overrides Sub OnStart(ByVal args() As String)Me.registroTxt.WriteLine("Sevice OnStart. " & Now())Me.registroTxt.WriteLine()Me.registroTxt.Flush()''AddHandler Me.Timer1.Elapsed, AddressOf OnTimer' intervalo dado en segundos Me.Timer1.Interval = 600000 ' => pb! cada 10 min (cifra en miliseg)' worker threadMe.Timer1.AutoReset = True' dispara accionMe.Timer1.Enabled = True'-'End SubPublic Sub OnTimer(ByVal source As Object, ByVal e As ElapsedEventArgs)Me.registroTxt.WriteLine("Sevice OnTimer. " & Now())Me.registroTxt.WriteLine()Me.registroTxt.Flush()Me.iniciar()End SubProtected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your service.
Me.Timer1.Enabled = FalseEnd Sub#
Region "Mariam..."Private Sub iniciar()...End Sub#
End Region
Any examples, suggestions? Tips... ? I'd appreciate it very much.
As always, thanks a lot!!!
Hi MariamCR,
The code is ok but, the service must use a proper user account.
If you want it to run the program when you start it, you must
This works for me
Best regards,
Umut