Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get WidgetHost and WidgetCatalog objects safely #2625

Merged
merged 12 commits into from
Apr 15, 2024

Conversation

krschau
Copy link
Collaborator

@krschau krschau commented Apr 12, 2024

Summary of the pull request

Since WidgetHost and WidgetCatalog objects are out of process, they can disappear out from under us throwing COMExceptions and crashing Dev Home. This will happen, for example, if the WidgetService.exe process dies while Dev Home is running.

Before, we saved the WidgetHost and WidgetCatalog objects in the WidgetHostingService, and handed them out so that different parts of the Dashboard could call methods on them. This was unsafe, since there was no guarantee the objects were still alive. Instead we put the relevant methods in the Service itself, so the Service can handle ensuring the object is still good and recovering if it has died. Even in the error case, the caller does not have to worry about exceptions being thrown by these methods.

#2620 relies on this change to get valid WidgetHost objects, so that there we can get valid Widget objects from the WidgetHost.

References and relevant issues

Detailed description of the pull request / Additional comments

Validation steps performed

PR checklist

@krschau krschau force-pushed the user/krschau/com-wrapper-hosting branch from b22e679 to 477326c Compare April 15, 2024 15:21
@krschau krschau added the Needs-Second Pull request that needs another approval label Apr 15, 2024
@@ -123,8 +123,12 @@ private async void OnRemoveWidgetClick(object sender, RoutedEventArgs e)

private async Task AddSizesToWidgetMenuAsync(MenuFlyout widgetMenuFlyout, WidgetViewModel widgetViewModel)
{
var widgetCatalog = await Application.Current.GetService<IWidgetHostingService>().GetWidgetCatalogAsync();
var widgetDefinition = await Task.Run(() => widgetCatalog.GetWidgetDefinition(widgetViewModel.Widget.DefinitionId));
var widgetDefinition = await Application.Current.GetService<IWidgetHostingService>().GetWidgetDefinitionAsync(widgetViewModel.Widget.DefinitionId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to try catch Wdiget.DefinitionId?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. I'm going to wrap the Widget object next (#2620) and I have a local branch where I'm wrapping WidgetDefinitions and WidgetProviderDefinitions, too.

// Show the providers and widgets underneath them in alphabetical order.
var providerDefinitions = await Task.Run(() => catalog!.GetProviderDefinitions().OrderBy(x => x.DisplayName));
var widgetDefinitions = await Task.Run(() => catalog!.GetWidgetDefinitions().OrderBy(x => x.DisplayTitle));
var providerDefinitions = (await _hostingService.GetProviderDefinitionsAsync()).OrderBy(x => x.DisplayName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding try/catch for this method if the DisplayName property is performing an out-of-proc operation

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will come in same wrapping change mentioned above.

@krschau krschau removed the Needs-Second Pull request that needs another approval label Apr 15, 2024
@krschau krschau merged commit 89bb82a into main Apr 15, 2024
4 checks passed
@krschau krschau deleted the user/krschau/com-wrapper-hosting branch April 19, 2024 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dashboard crashing
4 participants