1

I've got a problem with starting automatically my own C# service in win2k8. Basically service it self monitors a folder in a loop for changes (since the file system limitations). When I set service for autostart (or delayed start) it is in started state but does nothing. After that when I restart it manually everything starts working fine...

Here is my onStart method:

protected override void OnStart(string[] args)
{
  if (timer == null)
  {
    timer = new System.Timers.Timer();
    timer.AutoReset = false;
    timer.Interval = 1;
    timer.Elapsed += new System.Timers.ElapsedEventHandler(DoStuff);
  }
  eventLog1.WriteEntry("In OnStart");
  timer.Start();
}
Ramashankar
  • 1,438
  • 10
  • 14
mika
  • 57
  • 1
  • 5
  • check the windows event log, see if there're errors – Matt Feb 27 '14 at 13:33
  • 1
    Do you ever see your event log entry? What does the timer do? – mason Feb 27 '14 at 13:33
  • Possible duplicate: http://stackoverflow.com/questions/11015189/automatic-vs-automatic-delayed-start – alan Feb 27 '14 at 13:34
  • 2
    Not really related but did you consider using FileSystemWatcher instead of looping through files in the folder? http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher(v=vs.90).aspx – Fedor Hajdu Feb 27 '14 at 13:35
  • Did you try to wide delay for at least 5 minutes? – Rodion Feb 27 '14 at 13:46
  • Read the answer at the link I posted, it answers your question. Delayed and automatic start are intended for use at boot, not after. http://stackoverflow.com/questions/11015189/automatic-vs-automatic-delayed-start – alan Feb 27 '14 at 13:51
  • FileSystemWatcher is very cool but it is not working on GPFS, thats why Iam watching folder for changes in a loop. Event log is clear. Timer calls "DoStuff" every 60 sec. Here is a code at the end of DoStuff: TimeSpan ts = DateTime.Now.Subtract(LastChecked); TimeSpan MaxWaitTime = TimeSpan.FromMinutes(1); if (MaxWaitTime.Subtract(ts).CompareTo(TimeSpan.Zero) > -1) timer.Interval = MaxWaitTime.Subtract(ts).TotalMilliseconds; else timer.Interval = 1; timer.Start(); – mika Feb 27 '14 at 14:14

0 Answers0