fio
fio

Reputation: 25

System.Threading.Tasks does not contain method Wait();?

enter code here

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();

Hi, my question is, why in last line I have error which said: "Error 1 'System.Threading.Thread' does not contain a definition for 'Wait' and no extension method 'Wait' accepting a first argument of type 'System.Threading.Thread' could be found (are you missing a using directive or an assembly reference?)

It looks like, this method does not be included in Sys.Thr.Task. namespace.

Thank you for your time.

Upvotes: 0

Views: 909

Answers (1)

Cory Nelson
Cory Nelson

Reputation: 29981

You are confusing Task.Wait() with Thread.Join().

Upvotes: 1

Related Questions