private void _WindowTab_SelectionChanged(object sender, SelectionChangedEventArgs e) { var NewTab = ((TabItem)WindowTab.SelectedItem).Header.ToString(); if (NewTab != ActiveTab) { // Clear Sort Variables _TableSort = new SortDescription(null, ListSortDirection.Descending); _TableHead = new int[2] { -1, -1 }; ActiveTab = NewTab; _FindTab(NewTab).TaskGrid.SelectedItem = null; if (_MonitorTask != null && _MonitorTask.IsCompleted) { // Restart Task (Died for some reason?) _MonitorTask = Task.Run(() => _MonitorThread.MonitorLoop()); Console.WriteLine("Respawned Async update"); } else { // Trigger async update of tab if (_MonitorThread != null) { _MonitorThread.TriggerUpdate(); } } } }
private void _UpdateTask() { // Create Task _MonitorThread = new MonitorThread(this); _MonitorThread.ProgressUpdate += (s, e) => Dispatcher.Invoke(new Action(() => _UpdateFrontend(e))); // Start Task _MonitorTask = Task.Run(() => _MonitorThread.MonitorLoop()); }