views:

477

answers:

3

Hi,

I have a windows service which has a number of threads that do some work. All has been going well in testing, until once, where I saw "windows service terminated unexpectedly" in the event viewer.

How do I go about trying to debug where this is happening? I have exceptions being caught under normal circumstances but not in this case.

I do not know where to start.

JD.

+2  A: 

here you can find How to: Debug Windows Service Applications

ArsenMkrt
+1  A: 

Put a call to System.Diagnostics.Debugger.Break() in your OnStart() callback. When your service starts up, you'll be prompted to start the Visual Studio debugger. Once the debugger opens, you can debug from there.

Matt Davis
The problem I have is the windows service dies and I cannot reproduce it. How will debugging it help? Somewhere an unhandled exception is being thrown. I have try/excepts in my code but clearly the exception is not being caught.
JD
If the service is at least making it into your OnStart() callback, then put the call to Debugger.Break() in as I said. As soon as the debugger pops up and stops at your breakpoint, go to the Debug menu and select the Exceptions option. Click the checkbox under the Thrown column for the Common Language Runtime Exceptions. When you continue the debugging session, the debugger will break where the exception is <b>thrown</b> as opposed to where it is caught.
Matt Davis
You can even put the Debugger.Break() call in the entry point function for your service, which is even earlier in the startup process (obviously) than the OnStart() callback. Do this in case you never make it to your OnStart() callback.
Matt Davis
Thanks, did not know about that way of debugging. That has helped. I now have a clue where the unhandled exception is occurring.
JD
A: 

i am also encounter same error please find the event log detail below. any help will be great

Log Name:  System
Source:  Service Control Manager
Date:   21-07-2010 16:42:07
Event ID:  7034
Task Category: None
Level:   Error
Keywords:  Classic
User:   N/A
Computer:  
Description:
The AppFabric Caching Service service terminated unexpectedly. It has done this 5 time(s).
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"&gt;
 <System>
 <Provider Name="Service Control Manager" Guid="{555908D1-A6D7-4695-8E1E-26931D2012F4}" EventSourceName="Service Control Manager" />
 <EventID Qualifiers="49152">7034</EventID>
 <Version>0</Version>
 <Level>2</Level>
 <Task>0</Task>
 <Opcode>0</Opcode>
 <Keywords>0x80000000000000</Keywords>
 <TimeCreated SystemTime="2010-07-21T14:42:07.000Z" />
 <EventRecordID>13342</EventRecordID>
 <Correlation />
 <Execution ProcessID="0" ThreadID="0" />
 <Channel>System</Channel>
 <Computer>
 <Security />
 </System>
 <EventData>
 <Data Name="param1">AppFabric Caching Service</Data>
 <Data Name="param2">5</Data>
 </EventData>
</Event>

thanks for any help

kazim

kazim mehdi