开发者

Debugging a C# GUI

开发者 https://www.devze.com 2023-03-14 18:41 出处:网络
Overview: I am debugging a C# GUI that takes in an XML file and starts a new Process to perform statistical calculations on the XML file. The process for some reason is exiting in the middle of execut

Overview: I am debugging a C# GUI that takes in an XML file and starts a new Process to perform statistical calculations on the XML file. The process for some reason is exiting in the middle of execution with no apparent errors. A windows message box appears and says " has stopped worked, Windows is searching for a solution"

What I've tried:

  • I tried writing to a log to trace the execution of the application so I can see where it fails, but the process seems to exit at different points in the program开发者_高级运维.
  • I tried using Visual studios debugger to follow the program execution, but similarly the

    process exits at different times.

What I'd like to know:

  • Are there any other free debuggers I could try?
  • Are there any calls I can make to see the current state of the process while it's running?
  • Can anyone think of anything else to try?

any help would be great. Thanks.


Visual Studio's debugger is the best debugging tool ever written, you should focus more on learning to use it than looking for anything else.

To answer your question, go to Debug>Exceptions (CTRL+D CTRL+E) and tick the Thrown box next to Common Language Runtime Exceptions. This will cause the debugger to break whenever an exception is being thrown, regardless if you quietly swallow it or completely ignore it. This should help pinpoint your problem.


Adding some

Debugger.Break();

statements at strategic points in your code to force you into the debugger can be a useful way to troubleshoot stuff like this...

Just don't forget to take them out!


You could register for the AppDomain.CurrentDomain UnhandledException event to see if catches your problem.

Adding something like this in your Program.cs file before the main form is shown:

AppDomain.CurrentDomain.UnhandledException += 
    new UnhandledExceptionEventHandler(UnhandledExceptionEventOccured);

private static void UnhandledExceptionEventOccured(
    object sender, UnhandledExceptionEventArgs e)
{
    Exception ex = e.ExceptionObject as Exception;
    if(ex != null)
    {
        MessageBox.Show(ex.StackTrace, ex.Message);
    }
}

Another option would be to run your application through WinDbg

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号