private void Test_Click(object sender, RoutedEventArgs e) { if (!CheckIsValid()) return; BusyIndicator.IsBusy = true; Test.IsEnabled = false; var connector = new Connector(); connector.Adapter.InnerAdapters.Add(_editableAdapter); connector.Connected += () => { connector.Dispose(); GuiDispatcher.GlobalDispatcher.AddSyncAction(() => { new MessageBoxBuilder() .Text(LocalizedStrings.Str1560) .Owner(this) .Show(); BusyIndicator.IsBusy = false; Test.IsEnabled = true; }); }; connector.ConnectionError += error => { connector.Dispose(); GuiDispatcher.GlobalDispatcher.AddSyncAction(() => { new MessageBoxBuilder() .Text(LocalizedStrings.Str1561 + Environment.NewLine + error) .Error() .Owner(this) .Show(); BusyIndicator.IsBusy = false; Test.IsEnabled = true; }); }; connector.Connect(); }