Skip to content

Commit

Permalink
DYN-5245-DynamoRevit-Crash-WhenExiting (#13299)
Browse files Browse the repository at this point in the history
* DYN-5245-Revit-NotificationCenter-Crashing

I added some code for stopping the WebView2 instance when Dynamo is being closed because otherwise is crashing and also not loading the notifications.
Also the Dispose method was deleted due that we are doing the same in the new method added SuspendCoreWebviewAsync.

* DYN-5245-Revit-NotificationCenter-Crashing

Removing call to TrySuspendAsync();
  • Loading branch information
RobertGlobant20 authored and QilongTang committed Sep 7, 2022
1 parent a0229cb commit d2ab6e8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
42 changes: 27 additions & 15 deletions src/Notifications/NotificationCenterController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ internal NotificationCenterController(DynamoView view, DynamoLogger dynLogger)

dynamoView.SizeChanged += DynamoView_SizeChanged;
dynamoView.LocationChanged += DynamoView_LocationChanged;
notificationsButton.Click += NotificationsButton_Click;
notificationsButton.Click += NotificationsButton_Click;
dynamoView.Closing += View_Closing;

notificationUIPopup = new NotificationUI
{
Expand All @@ -89,6 +90,30 @@ internal NotificationCenterController(DynamoView view, DynamoLogger dynLogger)
}
}

private void View_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
dynamoView.Closing -= View_Closing;
SuspendCoreWebviewAsync();
}

async void SuspendCoreWebviewAsync()
{
notificationUIPopup.IsOpen = false;
notificationUIPopup.webView.Visibility = Visibility.Hidden;

if (notificationUIPopup.webView.CoreWebView2 != null)
{
notificationUIPopup.webView.CoreWebView2.Stop();
notificationUIPopup.webView.CoreWebView2InitializationCompleted -= WebView_CoreWebView2InitializationCompleted;
notificationUIPopup.webView.CoreWebView2.NewWindowRequested -= WebView_NewWindowRequested;

dynamoView.SizeChanged -= DynamoView_SizeChanged;
dynamoView.LocationChanged -= DynamoView_LocationChanged;
notificationsButton.Click -= NotificationsButton_Click;
notificationUIPopup.webView.NavigationCompleted -= WebView_NavigationCompleted;
}
}

private void InitializeBrowserAsync()
{
if (webBrowserUserDataFolder != null)
Expand Down Expand Up @@ -133,7 +158,7 @@ private void RequestNotifications()
}

CountUnreadNotifications();
notificationUIPopup.webView.NavigationCompleted += WebView_NavigationCompleted;
notificationUIPopup.webView.NavigationCompleted += WebView_NavigationCompleted;
}

private void CountUnreadNotifications()
Expand Down Expand Up @@ -202,19 +227,6 @@ private void WebView_CoreWebView2InitializationCompleted(object sender, Microsof
}
}

internal void Dispose()
{
notificationUIPopup.webView.CoreWebView2InitializationCompleted -= WebView_CoreWebView2InitializationCompleted;
if (notificationUIPopup.webView.CoreWebView2 != null)
{
notificationUIPopup.webView.CoreWebView2.NewWindowRequested -= WebView_NewWindowRequested;
}
dynamoView.SizeChanged -= DynamoView_SizeChanged;
dynamoView.LocationChanged -= DynamoView_LocationChanged;
notificationsButton.Click -= NotificationsButton_Click;
notificationUIPopup.webView.NavigationCompleted -= WebView_NavigationCompleted;
}

private void DynamoView_LocationChanged(object sender, EventArgs e)
{
notificationUIPopup.Placement = PlacementMode.Bottom;
Expand Down
1 change: 0 additions & 1 deletion src/Notifications/NotificationsViewExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public void Dispose()
BindingOperations.ClearAllBindings(notificationsMenuItem.CountLabel);
notificationsMenuItem = null;
disposed = true;
notificationCenterController.Dispose();
}
}

Expand Down

0 comments on commit d2ab6e8

Please sign in to comment.