last day (14 days later) » 

2:43 PM
2
A: Rerun service every x min with timer not working

ShadowI was in a bit same situation earlier. I used the following code, it worked for me. // The main Program that invokes the service static class Program { /// <summary> /// The main entry point for the application. /// </summary> static void Main() { ServiceBase[] Se...

 
So you dont call Main method? You just call RunProgram again? But don't you need to call Main because there is the Timer set?
 
The main method is called anyway when the service is run for the first time. And then all we have to need to re run the RunProgram
 
Hmm..With this code my scheduleTimer_Elapsed is never called at all
And how come when I press "start" in VS it just dies after Main(), shouldn't it be calling RunProgram() every min until I press stop?
 
In the above code the timer is set for 1000 milliseconds. Did you try placing a debugger in the RunProgramm. Does the controls gets in there? Can you please post the entire code?
 
I have updated now. The breakpoint WriteLine first time (called from main). But never from Elapsedevent
 
2:43 PM
My bad. I should not have talked about Main method. I am sorry. It is the protected override void OnStart(string[] args) method you have to write the first block. Updated the answer
 
Is the OnStart called automatically after Main? Note sure how that works. Will try your code
But my breakpoint never hits OnStart()..? Do I need to call it from Main?
 
Hello @krillezzz, I just now updated the code. That should help you.
 
hi
 
I have posted the full sample Program class and service class
 
I'll check
Maybe the problem is that I'm trying to debug without having the service installed?
because the breakpoint at OnStart(string[] args) never hits
when pressing "Start" in VS
 
2:48 PM
From your latest code I can see that you are not having the code related to run the service. And yes, you have to install the service
You have to install it every time you update the service
Yes, it should atleast reach the OnStart method
 
I have to go now, but you really helped. I will mark you as answer and try to fix it later
Many thanks!
 
Sure. Welcome
Thank you very much
 

last day (14 days later) »