本文介绍了背景工人重复dowork?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以通过科学计算器上的主要按钮检查器看到我的错误。后台工作人员似乎一遍又一遍地重复dowork部分,因为我在每个消息框中单击确定出现,另一个在
关闭之后直接上升,并且每个消息框关闭时进度条上升1%或更少...我已经摆弄它,但不能让它工作:(谢谢是提前....
hi can anyone see what I am doing wrong with some code from my prime button checker on my scientific calculator. the backgroundworker seems to repeat the dowork section over and over as I click ok in each messagebox comes up, another comes straight up after that one closes, and the progressbar goes up 1% or less with each messagebox closed... ive fiddled around with it but cant get it to work :( thanks is advance....
public static class PrimeTool
{
public static bool IsPrime(int primes)
{
// Test whether the parameter is a prime number.
if ((primes & 1) == 0)
{
if (primes == 2)
{
MessageBox.Show(primes + " Is Prime!");
}
else
{
MessageBox.Show(primes + " Is Not Prime!");
}
}
for (int k = 3;
(k * k) <= primes; k += 2)
{
if ((primes % k) == 0)
{
MessageBox.Show(primes + " Is Not Prime!");
}
}
return false;
}
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
for (int i = 1; (i <= 100); i++)
{
primes = Convert.ToInt32(textBox1.Text);
primes = int.Parse(textBox1.Text);
PrimeTool.IsPrime(primes);
backgroundWorker1.ReportProgress(i);
}
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
DateTime start = DateTime.Now;
TimeSpan timespent = DateTime.Now - start;
int timeleft = (timespent.Milliseconds / progressBar1.Value * (progressBar1.Maximum - progressBar1.Value));;
textBox4.Text = progressBar1.Value.ToString();
textBox3.Text = timeleft.ToString();
}
推荐答案
这篇关于背景工人重复dowork?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!