Link to home
Start Free TrialLog in
Avatar of b_levitt
b_levitt

asked on

WaitCursor Between forms often doesn't show up

I try to set Cursor.Current=Cursors.WaitCursor, when ever I have a long running operation.  However, I'm noticing, that sometimes it doesn't work or there is a significant delay.  The biggest culprit is when I set it before loading and showing a modal form, ie...

      Cursor.Current = Cursors.WaitCursor;
      Form formToLoad = null;
      switch (formNumber)
      {
        case "1":
          formToLoad = new App1MainMenu();
          break;
        case "2":
          formToLoad = new App2.FDEMainMenu();
          break;
      }
      if (formToLoad != null)
        formToLoad.ShowDialog();


If I break in the debugger prior to the showdialog line, it works fine.  Some ShowDialog trickery in my baseclass also works:

    private void BaseForm_Activated(object sender, EventArgs e)
    {
      Timer cursorTimer = new Timer();
      cursorTimer.Tick += new EventHandler(cursorTimer_Tick);
      cursorTimer.Interval = 500;
      cursorTimer.Enabled = true;

    }

    void cursorTimer_Tick(object sender, EventArgs e)
    {
      Cursor.Current = Cursors.Default;
      ((Timer)sender).Enabled = false;

    }


    new public DialogResult ShowDialog()
    {
      Cursor.Current = Cursors.WaitCursor;
      return base.ShowDialog();
    }


Is there a better way to do this?
ASKER CERTIFIED SOLUTION
Avatar of alexey_gusev
alexey_gusev
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Raymond-Holmboe
Raymond-Holmboe

also, Cursor.Show() may work, right after you change the cursor.
Avatar of b_levitt

ASKER

I appologize for the delay.  While I've not had a chance to test this fully, DoEvents did seem to work.  Cursor.Show did not.