在这里输入代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
namespace Threeeead
{
class ThreadDemo
{
public void Print1(Object obj1)
{
while (true)
{
Console.Write("1");
}
}
public void Print2()
{
while(true)
{
Console.Write("2");
}
}
static void Main(string[] args)
{
ThreadDemo objDemo= new ThreadDemo();
// Thread firstThread = new Thread (new ThreadStart(objDemo.Print1));
//firstThread.Start();
Thread secondThread = new Thread(new ThreadStart(objDemo.Print2));
secondThread.Start();
Thread thirdThread = new Thread(new ThreadStart (delegate()
{
while(true)
Console.Write("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
}));
thirdThread.Start();
ThreadPool.QueueUserWorkItem(new WaitCallback(objDemo.Print1));
// ThreadPool.QueueUserWorkItem(new WaitCallback(objDemo.Print2));
secondThread.Wait();
嗨,我的问题是,为什么在最后一行我有错误说: "错误1' System.Threading.Thread'不包含'等待'的定义并且没有延期方法'等待'接受第一个类型为System.Threading.Thread'可以找到(你错过了使用指令或程序集引用吗?)
看起来,这个方法不包含在Sys.Thr.Task中。命名空间。
感谢您的时间。
答案 0 :(得分:1)
您将Task.Wait()
与Thread.Join()
混淆。