请帮忙解决这个多线程的问题
操作代码:
private void Calc()
{
DateTime st = DateTime.Now;
//计算数值分段
step = (maxValue - minValue + 1) / threadNumber;
//获取当前线程名
long threadName = Convert.ToInt64(Thread.CurrentThread.Name);
//当前线程计算的开始值与结束值
beginNumber = minValue + step * (threadName - 1);
endNumber = beginNumber + step;
//累加数值
result = 0;
for (long i = beginNumber; i < endNumber; i++)
{
result++;
}
lock (this)
{
long sum = Convert.ToInt64(this.txtResult.Text);
sum += result;
this.txtResult.Text = sum.ToString();
}
DateTime et = DateTime.Now;
TimeSpan t = et - st;
string message = "线程 " + Thread.CurrentThread.Name + ": " + beginNumber.ToString() + "至 " +
endNumber.ToString() + ",耗时: " + t.TotalMilliseconds.ToString() + "毫秒 ";
&nb