Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

WaitCursor Between forms often doesn't show up

Posted on 2010-08-17
3
Medium Priority
?
1,035 Views
Last Modified: 2013-12-21
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?
0
Comment
Question by:b_levitt
3 Comments
 
LVL 24

Accepted Solution

by:
alexey_gusev earned 2000 total points
ID: 33455846
try

Application.DoEvents();

to force it processing all events
0
 
LVL 2

Expert Comment

by:Raymond-Holmboe
ID: 33463462
also, Cursor.Show() may work, right after you change the cursor.
0
 
LVL 11

Author Comment

by:b_levitt
ID: 33991402
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.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Loops Section Overview
Screencast - Getting to Know the Pipeline
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question