/// <summary> /// Starts the relay engine. /// </summary> private void StartRelayEngine() { Thread backGroundThread = new Thread(new ThreadStart(() => { try { TunnelRelayStateManager.InitializePlugins(); TunnelRelayStateManager.RelayRequestEventListener = this; TunnelRelayStateManager.StartTunnelRelayAsync().ConfigureAwait(false).GetAwaiter().GetResult(); this.Dispatcher.Invoke(new Action(() => { this.txtProxyDetails.Text = TunnelRelayStateManager.ApplicationData.HybridConnectionUrl + TunnelRelayStateManager.ApplicationData.HybridConnectionName; this.btnExportSettings.IsEnabled = true; })); } catch (Exception ex) { this.logger.LogError(ex, "Failed to establish connection to Azure Relay"); this.Dispatcher.Invoke(new Action(() => { this.txtProxyDetails.Text = "FAILED TO START AZURE PROXY!!!!"; this.btnExportSettings.IsEnabled = false; })); } })); backGroundThread.Start(); }
/// <summary> /// Raises the <see cref="Window.Closed" /> event. /// </summary> /// <param name="e">An <see cref="EventArgs" /> that contains the event data.</param> protected override void OnClosed(EventArgs e) { try { Parallel.ForEach(TunnelRelayStateManager.Plugins.Where(plugin => plugin.IsEnabled), (plugin) => plugin.InitializePlugin()); // Reload if the plugin configuration was changed. Task.Run(async() => await TunnelRelayStateManager.StartTunnelRelayAsync().ConfigureAwait(false)); } catch (Exception ex) { this.logger.LogError(ex, "Failed to set plugin settings"); MessageBox.Show("Plugin initialization failed!!", "Plugin management", MessageBoxButton.OKCancel, MessageBoxImage.Error); } base.OnClosed(e); }