after reading this stack overflow page and this other one.
I didn't really found an answer to my question, I was asking myself why is my service stopping after one loop althought is works fine in debug mode (visual studio).
Here is the code I have
public partial class Service1 : ServiceBase
{
Timer t;
// some more stuff
public Service1()
{
InitializeComponent();
// some more stuff
t = new Timer();
t.Interval = 1000 * 5; // timer of 5 secs.
t.Elapsed += new ElapsedEventHandler(this.onTimer);
t.Start();
}
protected void onTimer(object sender, ElapsedEventArgs args)
{
t.Stop(); // stop the timer to prevent callung the function 2 times in parallel
int tag = 1;
while (tag == 1)
{
tag = doStuff(); // return 1 if it needs to continu looping, return 0 when done
}
t.Start();
}
}
My problem is that doStuff() gets called one time, loop only once, and never get called again (I know this thanks to a log.txt file that I din't show up in the exemple)