Hi world,
I have been working on a very simple windows service, that has a timer and every time it ticks it is supossed to add a line to a text file.
After I installed the service and I run it, It adds a line in the onStart ()and in the onStop() methods, but it doesn't do anything when it ticks.
Please, could somebody help me
Thanks !!!!
Imports
System.ServiceProcessImports
System.DiagnosticsImports
System.IOPublic
Class AutoRebootService2 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.Interval = 1000
Timer1.Enabled =
TruearchivoLog(
"start", "c:/test.txt") End Sub Protected Overrides Sub OnStop() ' Add code here to perform any tear-down necessary to stop your service.Timer1.Enabled =
FalsearchivoLog(
"stop", "c:/test.txt") End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.TickarchivoLog(
"10 secs", "c:/test.txt") End Sub Public Sub archivoLog(ByVal errorDescription As String, ByVal path As String) Dim objStreamWriter As StreamWriterobjStreamWriter = File.AppendText(path)
objStreamWriter.WriteLine(errorDescription)
objStreamWriter.Close()
End SubEnd
Class
Timer within Windows Service not working
PMancini
It is considered invalid to show a form from a Service. There are several reasons, one being that there may not be a user logged on and no desktop to show the form on. Security and permissions can become another issue.
Normally you would have a service and a seperate application that uses a ServiceController component to communicate with the service.
All that being said, this may not be the best solution for your problem. If you're going to want the UI anyway, you can probably just use the Windows Task Scheduler to run your app on a regular schedule. You can find it in Start -> All Programs -> Accessories -> System Tools -> Task Scheduler.
-EDIT-
Forgot to mention that the Task Scheduler is accessible via the AT command so if you want, you can have your application create the scheduled task itself. Just use System.Diagnostics.Start() to run the AT command with the appropriate arguments.
Stem_penguin
Hi the service starts and stays running, and like I said when I stop it after some minutes, I check my text file and it contains only to lines:
start
stop
But I don't know why it doesn't do anything when the timer ticks.
I need to deploy an application to 40 computers and it needs to be run at 2:00am every night, and I though that having a windows service checking the time would be the solution but It has been way painful since I started with this
Do you have any suggestions
Thank you so much for you reply.
red60man
Does the service stay running once you start it Or does it start and then stop Normally you would start a long running process of some sort - often a loop. I'm not sure whether the Timer's thread counts or not...
Patch77
thank you so much for your reply rkimble,
But as far as I concern you have to specify an account in order to run a schedule task right
I wouldn't like to hard code the user name and not mention the password.
Can I use the localsytem account
I will do some research about the ServiceController component. do you suggest any information source
One more thing, this is even more important, how do you deploy a windows service
How do you run :
InstallUtil "c:\path\myservice"
from the setup project
THANKS !!!!
EmekaAwagu
I also had a problem finding this one. Turns out that for searching ... "Setup Windows Service" are the right keywords. The following article solves the problem...
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.KB.v10.en/enu_kbvcsharpnetkb/vcsharpnetkb/816169.htm
Specifically the following part...
Notice that Primary output appears under Install, Commit, Rollback and Uninstall.
Hope this helps you. Took me an hour to find it. There is just too much information...
sathish_indian
Hi world, I have changed my code so that the windows service won't be in charge of checking the computer time, instead I will have a form, actually I need this user interface.
Anyway in my OnStart method I try to show the form, but the form shows and then freezes, and it will be labeled as:
frmReboot is not responding....
Protected Overrides Sub OnStart(ByVal args() As String)Dim SecondForm As New frmReboot
SecondForm.Show()
End Sub
Can somebody help me please