backgroundWorker1_ProgressChanged问题 [英] backgroundWorker1_ProgressChanged Problem

查看:223
本文介绍了backgroundWorker1_ProgressChanged问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

我有一些可与后台工作人员一起工作的代码.
现在,我有了一些方法,当它们在doWork()中执行时,我想向用户显示一些状态,以便在用户等待操作完成时得到通知.

我有以下代码:

Hi guys..

I have some code that works with background worker.
Now, I have some methods which while they are executing in doWork() I want to show some status for the user in order to be notified what''s happening while he waits the action to be completed.

I have this code:

private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
  if (methodMode == 1)
  {
    txt_Note.SetStatusAndText("Preparing summary ");
  }
  else if (methodMode == 2)
  {
    txt_Note.SetStatusAndText("Saving Transaction...");
  }
  if (backMode == 3)
  {
    txt_Note.SetStatusAndText("Sending to MIDAS...");
  }
}



但是,当我执行它时,它引发了我无法从不同于当前线程的其他线程访问txt_Note的异常.

知道为什么会这样吗?

谢谢!



But when I execute it, it throws me exception that can not access txt_Note from different thread then the current one.

Any idea why is happening this?

Thanks!

推荐答案

您需要使用Invoke才能正确执行此操作.在下面的链接中,请看一下SetText方法.这将帮助您.

http://msdn.microsoft.com/en-us/library/ms171728% 28VS.80%29.aspx [ ^ ]

祝你好运!
You need to use Invoke to do this correctly. At the link below, have a good look at the SetText method. This will help you out.

http://msdn.microsoft.com/en-us/library/ms171728%28VS.80%29.aspx[^]

Good luck!


这篇关于backgroundWorker1_ProgressChanged问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆