I have a Windows Service that overrides the OnStart and OnStop methods to call a class library. I'm using a producer/consumer model (see http://www.albahari.com/threading/part4.aspx#_Wait_Pulse_Producer_Consumer_Queue for where I got the idea/logic).
The problem I'm having is the Action isn't correctly running for some reason. Here's the "(System.)Action" code (inside the timer_elapsed):
_queue.EnqueueItem(() =>
{
BuildFile file = new BuildFile();
file.run();
_writer.WriteLine("Gets Here: {0}", DateTime.Now.ToString());
_writer.Flush();
});
As you can probably see, the _writer is basically a "debug" logging tool. It DOES write that line out to the file whenever it is called (the Windows Service runs off a timer):
_timer.Interval = 30000; //(3600000)
_timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
_timer.Enabled = true;
For a test, the VERY first call that is made for BuildFile
is a simple log to the database:
public BuildFile()
{
logEntry("Success", "I'm Running...");
}
but the log entry never gets written (the method works fine elsewhere).
The weirdest part is when I wrap the class with a Console app, it works fine. The code is exactly the same in the Windows Service, but it just won't fire the BuildFile stuff.
Has anyone seen anything like this?
The console app and the service app are most likely running under different accounts. Make sure the service account has access to the file system path. Also, if you are using Windows Authentication for the database you need to look into that as well.