System.Environment.Exit crashes in Windows 8 in MainWindow-Closed event RRS feed

  • Question

  • Hello,

    our software GUI is WPF based, the core algorithms are native c++ with .NET as well as native Win32/C-based background threads.

    In the past, we used System.Environment.Exit(0) to ensure correct closing of the application with all of its background threads in MainWindow-Closed event (which was required to avoid hanging/delays while native c++ background threads were running in mathematical calculations or waiting for hardware events).

    This worked fine, until we used our software on Windows 8.

    In Windows 8, a crash happens right in the System.Environment.Exit(0) call. Similar experiences are posted here:


    The only workaround we could find to avoid this crash was, to put a DoEvents call right before the Exit function ( System.Windows.Forms.Application.DoEvents ), but this also seems dangerous.

    So the question is: What is the correct way to have a fast Shutdown inse the Main-Window close event in Windows 8, that ensures the fast termination of all background threads (native and managed threads)?

    Of course, we want a normal program termination with our supplied exit code (0) and no error reported to event log or anything.


    • Edited by mgexo Thursday, October 10, 2013 3:02 PM
    Thursday, October 10, 2013 2:25 PM