0

On launching my WPF application, I try to see if a particular required exe is running or not. If that is not running, I throw InvalidOperationException like this

if (gaInterface.ConnectToGA() != 0)
            throw new InvalidOperationException(Properties.Resources.GAConnectionErrorText);

  private void Application_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
    {
        var exception = e.Exception;
        ShowErrorMessage(exception);
        if (string.CompareOrdinal(exception.Message, FP.Properties.Resources.GAConnectionErrorText) == 0 || (
            !ReferenceEquals(exception.InnerException, null) &&
            string.CompareOrdinal(exception.InnerException.Message, FP.Properties.Resources.GAConnectionErrorText) == 0))
            e.Handled = false;
    }

e.Handled does get set to true, but only in Release mode application crashes after this. What could be the reason here?

halfer
  • 19,824
  • 17
  • 99
  • 186
WAQ
  • 2,556
  • 6
  • 45
  • 86

1 Answers1

1

Set e.Handled to true and then shutdown the application.

private void Application_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
    var exception = e.Exception;
    ShowErrorMessage(exception);
    if (string.CompareOrdinal(exception.Message, FP.Properties.Resources.GAConnectionErrorText) == 0 || (
        !ReferenceEquals(exception.InnerException, null) &&
        string.CompareOrdinal(exception.InnerException.Message, FP.Properties.Resources.GAConnectionErrorText) == 0))
        {            
             e.Handled = true;
             Application.Current.Shutdown();
        }
}
fhnaseer
  • 7,159
  • 16
  • 60
  • 112