开发者

Finding SQL servers in WPF application

开发者 https://www.devze.com 2022-12-10 03:57 出处:网络
I\'m moving my old app from windows forms to WPF and have encountered an error with underlined lines in this method. Could anyone help with that problems on DoEvents; SuspendLayout; ResumeLayout. My o

I'm moving my old app from windows forms to WPF and have encountered an error with underlined lines in this method. Could anyone help with that problems on DoEvents; SuspendLayout; ResumeLayout. My old method:

private void FindDataBases()
{
   string tempDBName = comboBoxDataBases.Text;

   // ((FrameworkElement) this).Cursor = Cursors.WaitCursor;
   ((FrameworkElement)this).Cursor = Cursors.Wait;

   Application.DoEvents();

   SuspendLayout();

   DataSet dataBases = GetDatabases();

   ((FrameworkElement) this).Cursor = Cursors.Default;
   Application.DoEvents();

   if ((dataBases != null) && (dataBases.开发者_StackOverflow中文版Tables[0].Rows.Count > 0))
   {
      comboBoxDataBases.DisplayMember = "DbName";
      comboBoxDataBases.DataSource = dataBases.Tables[0];

      if (comboBoxDataBases.FindStringExact(tempDBName) > 0)
      {
         comboBoxDataBases.SelectedIndex = comboBoxDataBases.FindStringExact(tempDBName);
      }
   }
   else
   {
      comboBoxDataBases.DataSource = null;
   }

   ResumeLayout();

   // this.comboBoxDataBases.Focus();
}


I'd try not to block the application while enumerating the databases. How about letting a background thread do the work? Maybe a BackgroundWorker? Lock the UI when the background thread starts, unlock the UI when it's done. AFAIK there's no such thing as Application.DoEvents() in WPF anymore...

0

精彩评论

暂无评论...
验证码 换一张
取 消