TOP KEK
TOP KEK

Reputation: 2651

Show waiting cursor while starting and loading application

I'm trying to show waiting cursor while my application initializes after clicking on exe file. My code is below

public MainWindow(string FileName):this()
{
    this.Cursor = Cursors.WaitCursor;
    //some init code
}

But cursor does change only for a moment of second. How to change it for the whole period my some init code executes?

UPD: instantiation of the main window looks like this in Program.cs

mainWindow = new MainWindow(args[0]);
 Application.Run(mainWindow);

Upvotes: 2

Views: 17873

Answers (5)

Khaled Eltabei
Khaled Eltabei

Reputation: 61

be sure that your form is Enabled

this.Enabled = true;
this.Cursor = Cursors.WaitCursor;
.....

Upvotes: 0

Hemant Kumar
Hemant Kumar

Reputation: 4611

You can do as given below

//Set the Cursor when app begins 
Cursor.Current = Cursors.WaitCursor;

//write your Code here 

//Change the Cursor to Default 
Cursor.Current = Cursors.Default;

I hope this could help you :-)

Upvotes: 0

udaya726
udaya726

Reputation: 1020

Try this

//Set the cursor to appear as busy
Cursor.Current = Cursors.WaitCursor;

---Execute your code-------

//Make the Cursor to default
Cursor.Current = Cursors.Default;

Upvotes: 8

Sergey Berezovskiy
Sergey Berezovskiy

Reputation: 236218

Doing a lot of stuff in form's constructor is not very desired.

Also users will not be very happy watching wait cursor instead of your form. Good practice is to inform user about whats happening in your application. I'd prefer to see form with message Initializing... please wait instead of thinking that your application has some problems and it just can't start quickly like all other exe files.

Marek Dzikiewicz suggestion is correct, if you want to leave things as is.

Upvotes: 2

Marek Dzikiewicz
Marek Dzikiewicz

Reputation: 2884

Try this:

Application.UseWaitCursor = true

Upvotes: 2

Related Questions