这是代码:
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();
}));
所以我认为正确的方法是使用进度报告并在进度报告事件中使用此 listBox 更新。而不是在 DoWork 事件中调用 cpuView 和 gpuView。