这是代码:我应该如何报告以报告背景工作者DoWork活动的进展情况?
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
while (true)
{
if ((worker.CancellationPending == true))
{
e.Cancel = true;
break;
}
else
{
if (tempCpuValue >= (float?)nud1.Value || tempGpuValue >= (float?)nud1.Value)
{
soundPlay = true;
blinking_label();
NudgeMe();
}
else
{
soundPlay = false;
stop_alarm = true;
}
backgroundWorker1.ReportProgress(
}
}
}
我应该怎么放,或使用此:?backgroundWorker1.ReportProgress
( 我没有任何进展酒吧或一些我应该怎么办呢
在此之前,DoWork的事件是像这样:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
while (true)
{
if ((worker.CancellationPending == true))
{
e.Cancel = true;
break;
}
else
{
if (tempCpuValue >= (float?)nud1.Value || tempGpuValue >= (float?)nud1.Value)
{
soundPlay = true;
blinking_label();
NudgeMe();
}
else
{
soundPlay = false;
stop_alarm = true;
}
cpuView();
gpuView();
//Thread.Sleep(1000);
}
}
}
凡内cpuView()我有:
this.Invoke(new Action(() =>
{
data = new List<string>();
data.Add("Gpu Temeprature --- " + sensor.Value.ToString());
listBox1.DataSource = null;
listBox1.DataSource = data;
listBox1.Invalidate();
}));
所以我认为正确的方法是使用progrees报告并在进度报告事件中使用此listBox更新。而不是在DoWork事件中调用cpuView和gpuView。
汉斯那么解决它的更好的方法是使用一个简单的定时器?然后我会这样做。 – user2065612 2013-03-07 23:07:38
我将会删除backgroundworker,而只是使用一个简单的计时器吧? – user2065612 2013-03-07 23:07:59