private void ChoiceStage_Click(object sender, RoutedEventArgs e) { Task.Run(() => { if (streaming != null) { streaming.Stop(); } ServiceBusViewUpdate(1); isUpdatingServiceBus = true; lock (lockS) streaming = streamingStage; Dispatcher.Invoke(() => xState.Content = "Stage", System.Windows.Threading.DispatcherPriority.Background); streaming.Run(); StreamingViewUpdateStart(); }); }