C# update and append textbox value using backgroundworker process

后端 未结 5 1246
心在旅途
心在旅途 2020-12-31 05:09

I\'ve got a c# windows form app I threw together. It\'s fairly simple:\\

inputs:

  • text string
  • source folder path
  • destination folder
5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-31 05:46

    If you use a background worker you can use the ReportProgress method to return any integer, such as the number of records processed. It doesn't have to be a percentage. Then, in the ProgressChanged handler you can update your textbox. E.g.

    int count = e.ProgressPercentage;
    textBox1.Text = string.Format("{0} images processed.", count);
    

    If you don't want to use a background worker you can call Application.DoEvents() inside your loop. This will give the UI an opportunity to refresh itself and respond to user actions. But beware - it will slow your program a lot so you may want to call it only on every 100th iteration.

提交回复
热议问题