C#BackgroundWorker的报告字符串? [英] C# backgroundWorker reports string?

查看:250
本文介绍了C#BackgroundWorker的报告字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何举报一个字符串(如正在搜索文件。,找到的选择。)回到从一个BackgroundWorker我windows.form以及一个百分比。另外,我有一个包含我想在backgroundWorker_Work运行的方法的一大类。我可以通过Class_method()调用它;但我再无力报告我完成百分比或任何来自所谓的类,只能从backgroundWorker_Work方法。

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, I have a large class that contains the method I want to run in the backgroundWorker_Work. I can call it by Class_method(); but i am then unable to report my percentage done or anything from the called class, only from the backgroundWorker_Work method.

谢谢!

推荐答案

我假设WCF也有方法

public void ReportProgress(int percentProgress, Object userState);



所以只需使用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.
}



你会得到启动倒计时串回来ProgressChanged事件

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;
}

这篇关于C#BackgroundWorker的报告字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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