tags:

views:

30

answers:

1

Hello, 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.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();
}
A: 

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...

Thorsten Dittmar