当backgroundworker运行时,WPF更新文本框

时间:2021-03-13 09:17:41

I am trying to continuously update my TextBox while the BackgroundWorker is running.

我正在尝试在BackgroundWorker运行时不断更新我的TextBox。

The code I am using freezes my application:

我正在使用的代码冻结了我的应用程序:

worker.RunWorkerAsync();

int i = 1;

while (worker.IsBusy)
{
   myTextBox.Text = i;
   i++;
   System.Threading.Thread.Sleep(2000);
}

1 个解决方案

#1


0  

As mentioned in comments you must use BackgroundWorker.ReportProgress Method to update your UI elements...

如评论中所述,您必须使用BackgroundWorker.ReportProgress方法来更新UI元素...

#1


0  

As mentioned in comments you must use BackgroundWorker.ReportProgress Method to update your UI elements...

如评论中所述,您必须使用BackgroundWorker.ReportProgress方法来更新UI元素...