WindowsService.exe has encountered a problem and needs to close. We are sorry for the inconvenience
My service sometimes fails. It's not bad, and on windows 7 and windows server 2003, service restarts. But on windows XP I see message "WindowsService.exe has 开发者_StackOverflow中文版encountered a problem and needs to close. We are sorry for the inconvenience." I added my service to the list of applications that are to be excluded from error reporting. It did not help - message showing without "Send report" and "Don't send". The main problem in the fact that there is not unhandled exeption in my service. There is error in one dll (with unmanaged cod) and I can't correct it. How can I set my service so, that is work without this massages? Added: All my code in a try / catch block. Event log is "Faulting application WindowsService.exe, version 1.0.0.0, faulting module .dll, fault address 0x00010616."
Trying to catch this exception is a Bad Idea, an access violation is quite a nasty one. Subscribe to the AppDomain.CurrentDomain.UnhandledException event in your Main() method. In your event handler call Environment.Exit(1). This is not guaranteed to run, the unmanaged code might have started its own thread. The garlic cross you need for that one is SetUnhandledExceptionFilter(), you should write this in C++/CLI.
You can wrap the problematic code in a try
/ catch
block and log the exceptions.
Try wrapping the problematic code in a try/catch block, from here you can then use the exception data and write it to a log which could be used for error reporting or debugging.
I'm assuming you're developing in C#:
try/catch - C# Reference
As a rule of thumb:
- All direct methods in windows service must be wrapped in a try catch block
- All Service's OnStart must do a very minimum thing of starting a timer/looper/polling worker.
精彩评论