还是c#线程的问题,我开2个线程,如何让每个线程固定sleep60秒呢?
代码如下:
窗体load事件中启动线程的代码:
private void Form1_Load(object sender, EventArgs e)
{
threadGet1 = new Thread(new ThreadStart(doGetFromXml1));
threadGet2 = new Thread(new ThreadStart(doGetFromXml2));
threadGet1.Start();
threadGet2.Start();
}
两个线程的代码:
public void doGetFromXml1()
{
while (true)
{
//在这里添加让线程停顿60秒钟的语句,我用threadGet1.Sleep(60000),编译报错:无法使用实例引用来访问成员“System.Threading.Thread.Sleep(int)”;请改用类型名来限定它
}
}
public void doGetFromXml2()
{
while (true)
{
//在这里添加让线程停顿60秒钟的语句,我用threadGet2.Sleep(60000),编译报错:无法使用实例引用来访问成员“System.Threading.Thread.Sleep(int)”;请改用类型名来限定它
}
}
这是怎么回事?
------解决方案--------------------
C# code
public void doGetFromXml2()
{
while (true)
{
Thread.Sleep(60000)}
}}
------解决方案--------------------
------解决方案--------------------
threadGet2.Sleep(60000)
换成:
System.Threading.Thread.Sleep(60000)