C# System.Threading.Tasks不包含方法Wait();?
在这里输入代码C# System.Threading.Tasks不包含方法Wait();?,c#,multithreading,wait,C#,Multithreading,Wait,在这里输入代码 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) { whi
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.Threading.Thread’类型的第一个参数的扩展方法‘Wait’(是否缺少using指令或程序集引用?)
看起来,Sys.Thr.Task.namespace中不包含此方法
谢谢您的时间。您把
任务.Wait()
和线程.Join()搞混了
线程
不是任务
。当你搜索编译器错误时,你会找到解决方案。无论涉及何种类型,此消息始终表示相同的内容。此消息清楚地告诉你问题所在。谢谢,这是重点