protected override async Task InitializeAsync(System.Threading.CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); Application.Current.MainWindow.Loaded += (s, e) => { _mainWindow = (System.Windows.Window)s; _settings = Setting.Initialize(this); _settings.OnChanged.AddEventHandler(ReloadSettings); if (ProvidersHolder.Instance.Providers == null) { ProvidersHolder.Initialize(_settings, new List <IImageProvider> { new SingleImageEachProvider(_settings), new SlideShowImageProvider(_settings), new SingleImageProvider(_settings) }); } _imageProviders = ProvidersHolder.Instance.Providers; _imageProvider = _imageProviders.FirstOrDefault(x => x.ProviderType == _settings.ImageBackgroundType); _imageProviders.ForEach(x => x.NewImageAvaliable += InvokeChangeImage); NextImage.InitializeAsync(this, _settings) .FileAndForget("claudiaide/nextimage/initializeasync"); PauseSlideshow.InitializeAsync(this, _settings).FileAndForget("claudiaide/pauseslideshow/initializeasync"); ReloadSettings(null, null); }; Application.Current.MainWindow.Closing += (s, e) => { _imageProviders.ForEach(x => x.NewImageAvaliable -= InvokeChangeImage); if (_settings != null) { _settings.OnChanged.RemoveEventHandler(ReloadSettings); } }; Microsoft.VisualStudio.Shell.ThreadHelper.JoinableTaskFactory.RunAsync(async() => { try { await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); _settings = await Setting.InitializeAsync(this); if (_settings == null) { return; } _mainWindow = (System.Windows.Window)Application.Current.MainWindow; _settings.OnChanged.AddEventHandler(ReloadSettings); if (ProvidersHolder.Instance.Providers == null) { ProvidersHolder.Initialize(_settings, new List <IImageProvider> { new SingleImageEachProvider(_settings), new SlideShowImageProvider(_settings), new SingleImageProvider(_settings) }); } _imageProviders = ProvidersHolder.Instance.Providers; _imageProvider = _imageProviders.FirstOrDefault(x => x.ProviderType == _settings.ImageBackgroundType); _imageProviders.ForEach(x => x.NewImageAvaliable += InvokeChangeImage); await NextImage.InitializeAsync(this, _settings); await PauseSlideshow.InitializeAsync(this, _settings); ReloadSettings(null, null); } catch { } }).FileAndForget("claudiaide/initializeasync"); }
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); Application.Current.MainWindow.Loaded += (s, e) => { ThreadHelper.ThrowIfNotOnUIThread(); _mainWindow = (Window)s; _settings = Setting.Initialize((DTE)GetService(typeof(DTE))); _settings.OnChanged.AddEventHandler(ReloadSettings); if (ProvidersHolder.Instance.Providers == null) { ProvidersHolder.Initialize(_settings, new List <ImageProvider> { new SingleImageEachProvider(_settings), new SlideShowImageProvider(_settings), new SingleImageProvider(_settings), new SingleImageWebProvider(_settings), new WebApiImageProvider(_settings) }); } _imageProviders = ProvidersHolder.Instance.Providers; _imageProvider = _imageProviders.FirstOrDefault(x => x.ProviderType == _settings.ImageBackgroundType); _imageProvider.IsActive = true; _imageProviders.ForEach(x => x.NewImageAvailable += InvokeChangeImage); NextImage.InitializeAsync(this) .FileAndForget("claudiaide/nextimage/initializeasync"); PauseSlideshow.InitializeAsync(this).FileAndForget("claudiaide/pauseslideshow/initializeasync"); SaveSolutionSettings.InitializeAsync(this, _settings) .FileAndForget("claudiaide/saveSolutionSettings/initializeasync"); ; ReloadSettings(null, null); }; Application.Current.MainWindow.Closing += (s, e) => { _imageProviders.ForEach(x => x.NewImageAvailable -= InvokeChangeImage); if (_settings != null) { _settings.OnChanged.RemoveEventHandler(ReloadSettings); } }; ThreadHelper.JoinableTaskFactory.RunAsync(async() => { try { await JoinableTaskFactory.SwitchToMainThreadAsync(true, cancellationToken); _settings = Setting.Initialize((DTE)await GetServiceAsync(typeof(DTE))); if (_settings == null) { return; } _mainWindow = Application.Current.MainWindow; _settings.OnChanged.AddEventHandler(ReloadSettings); if (ProvidersHolder.Instance.Providers == null) { ProvidersHolder.Initialize(_settings, new List <ImageProvider> { new SingleImageEachProvider(_settings), new SlideShowImageProvider(_settings), new SingleImageProvider(_settings), new SingleImageWebProvider(_settings), new WebApiImageProvider(_settings) }); } _imageProviders = ProvidersHolder.Instance.Providers; _imageProvider = _imageProviders.FirstOrDefault(x => x.ProviderType == _settings.ImageBackgroundType); _imageProvider.IsActive = true; _imageProviders.ForEach(x => x.NewImageAvailable += InvokeChangeImage); await NextImage.InitializeAsync(this); await PauseSlideshow.InitializeAsync(this); await SaveSolutionSettings.InitializeAsync(this, _settings); ReloadSettings(null, null); } catch { } }).FileAndForget("claudiaide/initializeasync"); }