3

My app takes a bit to start because the UI is pretty heavy. I want to show Cursors.AppWaiting cursor the moment the user double-clicks on the shortcut. So I pop Cursor.Current = Cursors.AppStarting; into the constructor of the main form. However, when I start the app, the cursor does not change until after the form is loaded.

Is there a way to change the cursor immediately after the user double-clicks the shortcut?

AngryHacker
  • 59,598
  • 102
  • 325
  • 594
  • 2
    Windows already does this, displays that cursor for up to 6 seconds. If it takes longer then you need a splash screen: http://stackoverflow.com/a/393870/17034 – Hans Passant Jan 18 '12 at 02:37

3 Answers3

4

Well, you can do the work using a Background Worker and UseWaitCursor property to change cursor.

var bw = new BackgroundWorker();
UseWaitCursor = true;
bw.DoWork += (s, e) =>
{
    //do work.. 
};

bw.RunWorkerCompleted += (s, e) =>
{
   Invoke((Action)(() => UseWaitCursor = false)); 
};
bw.RunWorkerAsync();
Kakashi
  • 2,165
  • 14
  • 19
3

Try adding

Application.DoEvents(); 

After changing the cursor.

Valamas
  • 24,169
  • 25
  • 107
  • 177
  • One of the *very few* (IMO) legitimate times to use Application.DoEvents() – Andrew Barber Jan 18 '12 at 00:58
  • @Andrew: Yes, I was hesitant to place it as an answer as it is one of those answers that someone on a bad day would down vote. – Valamas Jan 18 '12 at 01:40
  • @Andrew, I can't believe I heard you saying that ;) –  Jan 18 '12 at 02:29
  • @Halabi I clearly said and emphsized *very few*. Almost every other time I see it mentioned it is a *horrible* idea. – Andrew Barber Jan 18 '12 at 02:30
  • @Andrew I know what you said mate. I am just happy ;) –  Jan 18 '12 at 02:34
  • I'm *still* tempted to downvote this, and I'm having a great day. The reason I'm tempted to downvote is because you propose it as if it were "magic code", rather than explaining *why* this approach actually fixes the problem. Mention pumping the message loop to process a `WM_SETCURSOR` message or something that makes it clear this isn't a general fix for all sorts of UI problems, and I might even be tempted to upvote. No one argues that `DoEvents` is useless; they argue that it's misunderstood and almost always used inappropriately. Answers like this do little to curb that unfortunate reality. – Cody Gray - on strike Jan 18 '12 at 23:59
-1

Just collapse your MainGrid until the app is loaded

Converter Reference

<Window.Resources>
    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
</Window.Resources>

XAML ElementReference

 Visibility="{Binding Path=IsLoaded, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
MyKuLLSKI
  • 5,285
  • 3
  • 20
  • 39