diff --git a/New_Extensibility_Model/Samples/SettingsSample/MyToolWindow.cs b/New_Extensibility_Model/Samples/SettingsSample/MyToolWindow.cs index c7cb157a..725958ff 100644 --- a/New_Extensibility_Model/Samples/SettingsSample/MyToolWindow.cs +++ b/New_Extensibility_Model/Samples/SettingsSample/MyToolWindow.cs @@ -6,7 +6,6 @@ namespace SettingsSample; using System.Threading; using System.Threading.Tasks; using Microsoft.VisualStudio.Extensibility; -using Microsoft.VisualStudio.Extensibility.Commands; using Microsoft.VisualStudio.Extensibility.ToolWindows; using Microsoft.VisualStudio.RpcContracts.RemoteUI; @@ -16,7 +15,7 @@ namespace SettingsSample; [VisualStudioContribution] public class MyToolWindow : ToolWindow { - private object? dataContext; + private MyToolWindowData? dataContext; /// /// Initializes a new instance of the class. @@ -37,8 +36,7 @@ public MyToolWindow() public override Task InitializeAsync(CancellationToken cancellationToken) { this.dataContext = new MyToolWindowData(this.Extensibility); - - return Task.CompletedTask; + return this.dataContext.InitializeAsync(cancellationToken); } /// diff --git a/New_Extensibility_Model/Samples/SettingsSample/MyToolWindowControl.cs b/New_Extensibility_Model/Samples/SettingsSample/MyToolWindowControl.cs index 31d79e2e..1e95b6bc 100644 --- a/New_Extensibility_Model/Samples/SettingsSample/MyToolWindowControl.cs +++ b/New_Extensibility_Model/Samples/SettingsSample/MyToolWindowControl.cs @@ -17,12 +17,8 @@ internal class MyToolWindowControl : RemoteUserControl /// /// Data context of the remote control which can be referenced from xaml through data binding. /// - /// - /// Optional synchronizationContext that the extender can provide to ensure that - /// are executed and properties are read and updated from the extension main thread. - /// - public MyToolWindowControl(object? dataContext, SynchronizationContext? synchronizationContext = null) - : base(dataContext, synchronizationContext) + public MyToolWindowControl(object? dataContext) + : base(dataContext) { } } diff --git a/New_Extensibility_Model/Samples/SettingsSample/MyToolWindowData.cs b/New_Extensibility_Model/Samples/SettingsSample/MyToolWindowData.cs index 43227b31..9fa775bd 100644 --- a/New_Extensibility_Model/Samples/SettingsSample/MyToolWindowData.cs +++ b/New_Extensibility_Model/Samples/SettingsSample/MyToolWindowData.cs @@ -11,7 +11,6 @@ namespace SettingsSample; using Microsoft.VisualStudio.Extensibility; using Microsoft.VisualStudio.Extensibility.Settings; using Microsoft.VisualStudio.Extensibility.UI; -using Microsoft.VisualStudio.Threading; /// /// A sample data context object to use with tool window UI content. @@ -43,8 +42,6 @@ public MyToolWindowData(VisualStudioExtensibility extensibility) this.extensibility = Requires.NotNull(extensibility, nameof(extensibility)); this.UpdateCommand = new AsyncCommand(this.UpdateAsync); - - this.InitializeSettingsAsync(extensibility).Forget(); } /// @@ -77,13 +74,23 @@ public string SampleText set => this.SetProperty(ref this.sampleText, value); } + /// + /// Initializes the current instance of . + /// + /// Cancellation token to monitor. + /// Task indicating completion of initialization. + public Task InitializeAsync(CancellationToken cancellationToken) + { + return this.InitializeSettingsAsync(cancellationToken); + } + #pragma warning disable VSEXTPREVIEW_SETTINGS // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. - private async Task InitializeSettingsAsync(VisualStudioExtensibility extensibility) + private async Task InitializeSettingsAsync(CancellationToken cancellationToken) { - await extensibility.Settings().SubscribeAsync( + await this.extensibility.Settings().SubscribeAsync( [SettingDefinitions.SettingsSampleCategory], - CancellationToken.None, + cancellationToken, values => { if (values.TryGetValue(SettingDefinitions.AutoUpdateSetting.FullId, out ISettingValue? autoUpdateValue)) @@ -127,5 +134,6 @@ private void UpdateSampleTextFromSettings(SettingValues values) }; } } + #pragma warning restore VSEXTPREVIEW_SETTINGS // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. }