-
Notifications
You must be signed in to change notification settings - Fork 324
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
Conversation
b22e679
to
477326c
Compare
@@ -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); |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
tools/Dashboard/DevHome.Dashboard/Services/WidgetHostingService.cs
Outdated
Show resolved
Hide resolved
// 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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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