views:

78

answers:

2

I know the title may be misleading but i didn't knew how to describe in title.

I've wrote an application in C# 3.5 / MS SQL. Application is 90k lines big. I don't use many Try Catch clauses so when error happens it's usually displayed to user with dialog box saying would you like to Continue and the error message. But recently I've noticed on some very rare cases it crashes with known to all dialog that the program has crashed and would you like to send information to Microsoft about it. I couldn't replicate the problem on my own computer, and on other computer that I've tried. It happened so far 5 times on 2 different computers in 2 different places. It was reproducible on that one computer that when user was typing account number application was crashing. Problem disappeared 30 minutes later without me fixing anything.

Should I be worried? Or should i just ignore it like i do when Microsoft Outlook crashes with exactly same message? How to diagnose such behavior when everything works fine on my own development computer and i can't get it to crash either way?

With regards,

MadBoy

+2  A: 

If the problem has happened on several machines, several different times, you have a problem with code. Worse, it seems that you don't have a clue where the problem is coming from. Finding that out is step one.

Ask the users what they were doing when the program fell over. You need to try and get enough information that you can replicate the problem yourself. Failing that, when the crash dialog box comes up, get them to send you the details. The exception message might at least point you in the right direction.

Also, you really need to implement more thorough exception handling and testing, but I suspect you knew that already.

EDIT: Problems that occur on one machine but not another are often related to searching for something on the machine that the program cannot find (files/directories/registry entries/fonts etc.).

If the problem occurs only after the program has been used for a long time, it could be related to resource issues (are you using unmanaged code, or are you opening connections to things and not closing them?).

ANOTHER EDIT: If the program is crashing at times that seem unrelated to user activity, and you are using threads, then the problem is almost certainly related to something in a background thread.

As nobugz mentioned, logging your errors is a really great way to help you track down the problem (make sure to log the stack trace as well as just the exception message).

I'd consider things like connecting to databases and other apps as things that are likely to screw up (and are out of control of your application), so it is good practice to wrap these things in try/catch, if you haven't already.

Richie Cotton
Problem is that i actually seen that message myself, i saw where it crashed. I took time to go into exactly same place, i did several times what user did. I asked my colleague who has vista to try doing exactly the same thing and nothing happened. It happened 3 times for that one guy in that place and then stopped. The other 2 times were in other place and it happened just once or twice, and i wasn't able to replicate it either. Also like i said the exception message isn't the known to me usual Error message that i can track down. It's the Send Microsoft msg which contains no real information.
MadBoy
I've recently started using Using and Threads. I don't do/search for things on machine, especially in the case I've seen it crash. I only did SQL connection. And the program was crashing just couple of seconds after starting. It works fine now. No crashes... it works. It wasn't crashing on any other machine. The other crashes were probably related to using external Excel interop and things like that when many things were happening.
MadBoy
Also usually when i wasn't closing the connection or doing some other thing program was giving me real tips what's the problem. I am using some external libraries like MigraDoc, DocX and interops for Word / Excel but i don't use it in the place that was crashing the program.
MadBoy
+3  A: 

The Application.ThreadException event that displays the dialog can only catch a subset of all possible exceptions. It will only handle exceptions raised in event handlers that run in response to Windows messages.

To catch all exceptions, including ones on threads other than the UI thread, you'll need to write an event handler for AppDomain.CurrentDomain.UnhandledException. Log the e.ExceptionObject.ToString() return value, then call Environment.FailFast() to avoid telling Microsoft about your problems.

You ought to consider logging the Application.ThreadException handled exceptions as well. It really isn't safe for the user to click Continue.

Hans Passant
Could you suggest some good article or some book that would help me writing that handlers ? And how to use them?
MadBoy
This article covers both clearly and concisely: http://www.switchonthecode.com/tutorials/csharp-tutorial-dealing-with-unhandled-exceptions
Tom West