实现多线程的.public void Run()
{
Boolean end = false;
while (!end)
{
if (myArray.Count != 0)
{
Monitor.Enter(this);
GetHtml((String)myArray[0]);
myArray.RemoveAt(0);
}
else
{
LogTextBox.AppendText("执行完毕!");
end = true;
}
Monitor.Exit(this);
Thread.Sleep(5);
}
}
运行的时候会提示异常:从不同步的代码块中调用了对象同步方法。
错误行是:Monitor.Exit(this);
请问如何处理?
{
Boolean end = false;
while (!end)
{
if (myArray.Count != 0)
{
Monitor.Enter(this);
GetHtml((String)myArray[0]);
myArray.RemoveAt(0);
}
else
{
LogTextBox.AppendText("执行完毕!");
end = true;
}
Monitor.Exit(this);
Thread.Sleep(5);
}
}
运行的时候会提示异常:从不同步的代码块中调用了对象同步方法。
错误行是:Monitor.Exit(this);
请问如何处理?
public void Run()
{
Boolean end = false;
Monitor.Enter(this);
while (!end)
{ if (myArray.Count != 0)
{
GetHtml((String)myArray[0]);
myArray.RemoveAt(0);
}
else
{
LogTextBox.AppendText("执行完毕!");
end = true;
}
Thread.Sleep(5);
}
Monitor.Exit(this);
}