开发者

Finding SQL servers in WPF application

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜