System.Threading.Tasks不包含方法Wait();
本文关键字:Wait 方法 包含 Threading Tasks System | 更新日期: 2023-09-27 18:28:03
在此处输入代码
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"不包含"Wait"的定义,也找不到接受类型为"System.Threadion.Thread"的第一个参数的扩展方法"Wait"(是否缺少using指令或程序集引用?)
看起来,此方法未包含在Sys.Thr.Task.命名空间中。
谢谢你抽出时间。
您混淆了Task.Wait()
和Thread.Join()
。