1

I have a C# WPF app that display an error dialog with the error code 0xc0000005. I researched this error code and found that it is a access violation error and could be caused by several things including native code errors (p/invoke and 3rd party dlls). Restarting the app seems to clear the error but I want to be able to force the app to close when that error occurs. Since it is not a managed code exception it is not caught in the try catch blocks, is there any way to force the app to close when this error occurs?

2
  • This should normally bomb the app. What is preventing it from bombing? Post a screenshot if you can't describe it. Apr 13, 2011 at 0:10
  • I haven't been able to repro it but the error dialog comes up and the app seems to be running fine in the background. Once you close the dialog, though, it closes the app.
    – evanb
    Apr 13, 2011 at 16:59

1 Answer 1

1

You can catch native exceptions in different way. Either using Win32Exception or SEHException exception class or using catch without any exception type specified as

try
{}
catch
{}

Refer this for details: Can you catch a native exception in C# code?

Use Environment.Exit(0); to terminate your application.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.