When loading the application I fill TableAdapter . When it is filled in, it connects to the MS SQL server. If there is no connection, then the window freezes. How to start a connection in the background.
private void Window_Loaded(object sender, RoutedEventArgs e) { try { monitorDataSet = ((BidsMonitor.MonitorDataSet)(this.FindResource("monitorDataSet"))); // Загрузить данные в таблицу BidsView. Можно изменить этот код как требуется. bidsTA = new BidsMonitor.MonitorDataSetTableAdapters.BidsViewTableAdapter(); System.Windows.Data.CollectionViewSource bidsVS = ((System.Windows.Data.CollectionViewSource)(this.FindResource("bidsViewViewSource"))); this.statusIndicator.Fill = Brushes.Yellow; this.statusText.Text = "Подключение ..."; this.statusText.Dispatcher.Invoke(new Action(() => { try { // В следующей строке происходт подключение к серверу и считываение данных bidsTA.Fill(monitorDataSet.BidsView); bidsVS.View.MoveCurrentToFirst(); this.statusIndicator.Fill = Brushes.Green; this.statusText.Text = "Подключено"; this.updateTimeTextbox.Text = string.Format("Обновлено: {0}", DateTime.Now.ToString()); } catch { this.statusIndicator.Fill = Brushes.Red; this.statusText.Text = "отсутствует"; } }), DispatcherPriority.Background); } catch(Exception ex) { MessageBox.Show(ex.ToString()); } }