C# backgroundWorker reports string?

后端 未结 4 1707
[愿得一人]
[愿得一人] 2021-01-11 16:24

How can I report a string (like \"now searching file. . .\", \"found selection. . .\") back to my windows.form from a backgroundWorker as well as a percentage. Additionally,

4条回答
  •  鱼传尺愫
    2021-01-11 16:47

    I'm assuming WCF also have the method

    public void ReportProgress(int percentProgress, Object userState); 
    

    So just use the userState to report the string.

    private void worker_DoWork(object sender, DoWorkEventArgs e)
    {
     //report some progress
     e.ReportProgress(0,"Initiating countdown");
    
    // initate the countdown.
    }
    

    And you'll get that "Initiating countdown" string back in ProgressChanged event

    private void worker_ProgressChanged(object sender,ProgressChangedEventArgs e) 
    {
      statusLabel.Text = e.UserState as String;
    }
    

提交回复
热议问题