Displaying wait cursor in while backgroundworker is running

后端 未结 9 1928
傲寒
傲寒 2020-12-30 03:50

During the start of my windows application, I have to make a call to a web service to retrieve some default data to load onto my application. During the load of the form, I

9条回答
  •  情话喂你
    2020-12-30 04:01

    In WPF, I've done this by setting the Mouse.OverrideCursor property to Cursors.Wait before I start the Backgroundworker, and then resetting it to null in the RunWorkerCompleted event. Seems to work pretty well so far.

    public void go()
    {
        BackgroundWorker thread = new BackgroundWorker();
    
        thread.DoWork += run;
        thread.RunWorkerCompleted += taskCompleted;
        thread.WorkerReportsProgress = true;
    
        // Change mouse cursor to busy
        Mouse.OverrideCursor = Cursors.Wait;
    
        thread.RunWorkerAsync();
    }
    
    private void taskCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
        // Reset mouse cursor
        Mouse.OverrideCursor = null;
    }
    

提交回复
热议问题