display Hourglass when application is busy

前端 未结 9 1675
说谎
说谎 2020-11-28 03:01

For a view constructed using WPF, I want to change the mouse cursor to a hourglass when the application is busy and nonresponsive.

One solution is to add



        
9条回答
  •  生来不讨喜
    2020-11-28 03:24

    I used Olivier Jacot-Descombes's solution, it's very simple and working well. thanks. update: it even works well without using a different threads/background worker.

    I use it with backgroudworker, mouse cursor looks great when it's busy working and return to normal when the work is done.

    public void pressButtonToDoSomeLongTimeWork()
    {    
        Mouse.OverrideCursor = Cursors.Wait;
        // before the long time work, change mouse cursor to wait cursor
    
        worker.DoWork += doWorkLongTimeAsync;
        worker.RunWorkerCompleted += worker_RunWorkerCompleted;
        worker.RunWorkerAsync();  //start doing some long long time work but GUI can update
    }
    
    private void worker_RunWorkerCompleted(object sender,     
                                           RunWorkerCompletedEventArgs e)
    {
        //long time work is done();
        updateGuiToShowTheLongTimeWorkResult();
        Mouse.OverrideCursor = null;  //return mouse cursor to normal
    }
    

提交回复
热议问题