简体   繁体   中英

Application crash after this.shutdown on windows 10

I am stuck at a suspicious problem in my C# / WPF / Prism application. I made a method to block the 2nd and more execution with the help of a mutex. This works fine with Windows 7. When I try to run this application with Windows 10 the application first starts as expected, the second start sometimes leads to only displaying my error message, but mostly my error message is displayed and after clicking OK on this, a windows dialog pops up displaying "Program has stopped working". In the event log of the Windows 10 System is a new Application log entry

Faulting application name: application.name, version: 0.1.11.0, time stamp: 0x5a01baef
Faulting module name: KERNELBASE.dll, version: 10.0.16299.15, time stamp: 0x2cd1ce3d
Exception code: 0xc000041d
Fault offset: 0x001008b2
Faulting process ID: 0x19bc
Faulting application start time: 0x01d357cfe3c8bc58
Faulting application path: 
Faulting module path: C:\WINDOWS\System32\KERNELBASE.dll
Report ID: 525f81c7-cccb-49f3-9c25-01c877056b83
Faulting package full name: 
Faulting package-relative application ID: 

If I add a Messagebox.Show statement after this.shutdown the procedure works fine under Windows 10 but this might not be a correct solution.

This thing only occures when the application is run via doubleclick on the exe running this in visual studio does not reproduce this misbehavior. I also attached a global exception handling which also does not bring this error.

Thanks for helping finding a solution.

EDIT: Minimal Example

protected override void OnStartup(StartupEventArgs e)
      {
         // Global exception handling
         Application.Current.DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler(AppDispatcherUnhandledException);

         try
         {
            // getting the settings
            ISettingsRepo _settingsRepo = new SettingsRepo();
            if (mutex.WaitOne(TimeSpan.Zero, true))
            {
               Bootstrapper bs = new Bootstrapper();
               bs.Run();

               mutex.ReleaseMutex();
            }
            else
            {
               var messageText = "nostart";
               MessageBox.Show(messageText, System.Windows.Application.Current.Resources["ApplicaionTitle"].ToString(), MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly);

               this.Shutdown();
            }
         }
         catch (Exception ex)
         {
            throw ex;
         }
      }

试试这个-Environment.Exit(0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM