Reputation: 677
I have a c# windows service that crashes without logging almost everyday after running for a few hours. Recently I added catch blocks to literally every method and still it doesn't help. Since I am using asynchronous callbacks on MSMQ, I guess there could be some multi-threading issues, but I have no clear clue. Any insight into this problem will be very helpful. Here is the pseudo code:
public MyService : ServiceBase
{
onStart()
{
try
{
someQueue.BeginReceive()
}
catch(Exception e)
{
log error and throw
}
}
void someQueue_ReceiveCompleted(object sender, ReceiveCompletedEventArgs e)
{
try
{
//process the message
}
catch(Exception e)
{
//log
}
finally
{
someQueue.Refresh()
someQueue.BeginReceive();
}
}
}
Upvotes: 1
Views: 2437
Reputation: 61
I know years passed since this request. But I got the same issue and no solution worked for me, other than the following. In my case, the Event Viewer was not giving any details about the crash, and all user rights were ok. the issue was a line of code in the OnStart method:
Debugger.Launch();
It was trying to launch the debugger, but that was not installed on that server. As such, it never completed and no exception was caught by my code. Got rid of that, and it started working.
Upvotes: 0
Reputation: 701
You can check Event Viewer to know the reason of Service getting stopped.
Open start menu and start Event Viewer, in application section you'll find the error
Upvotes: 2