Skip to content

Commit

Permalink
Update DynamoViewModel.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
pinzart90 committed Feb 2, 2024
1 parent bdff3b1 commit f15f891
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -795,8 +795,9 @@ private void CurrentDispatcher_UnhandledException(object sender, DispatcherUnhan
return;
}

// Try to handle the exception so that the host app can continue in most cases.
// In some cases Dynamo code might still crash after this handler kicks in. In these edge cases we might see 2 CER windows (the extra one from the host app)
// Try to handle the exception so that the host app can continue (in most cases).
// In some cases Dynamo code might still crash after this handler kicks in. In these edge cases
// we might see 2 CER windows (the extra one from the host app) - CER tool might handle this in the future.
e.Handled = true;

CrashGracefully(e.Exception);
Expand All @@ -822,18 +823,27 @@ internal void CrashGracefully(Exception ex, bool fatal = false)

if (fatal)
{
// Fatal exception. Close Dynamo and terminate the process.

// Run the Dynamo exit code in the UI thread since CrashGracefully could be called in other threads too.
UIDispatcher?.Invoke(() => {
try
{
Exit(false);
}
catch { }
}, DispatcherPriority.Send);


// We terminate the process here so that no other exceptions can leak to the host apps.
// All fatal exceptions will result in a process termination (either by Dynamo, host app or CLR)
Environment.Exit(1);
}
else
{
// Non fatal exception.

// We run the Dynamo exit call asyncronously in the dispatcher to ensure that any continuation of code
// manages to run to completion before we start shutting down Dynamo.
UIDispatcher?.BeginInvoke(() => {
try
{
Expand Down

0 comments on commit f15f891

Please sign in to comment.