unityゲーム開発-C#言語基礎編(マルチスレッド)

1296 ワード

··· class Program { static void Main(string[] args) {
        Console.WriteLine("---------");
        Thread The = new Thread(Show);
        The.Start();
        Console.WriteLine(" ");
        Console.ReadKey();
        Action ac = Show;
        ac.BeginInvoke(null, null);
        Thread.Sleep(1000);// 10 
        Console.WriteLine(" !");




        Thread the1 = new Thread(show1);
        the1.Start(99);


        Action a = Show;
        IAsyncResult res= a.BeginInvoke(null,null);

        if (res.IsCompleted)
        {
            Console.WriteLine(" " + Thread.CurrentThread.ManagedThreadId);
        }
        else {
            Console.WriteLine("meiwan"+Thread.CurrentThread.ManagedThreadId);
        }



       bool isEnd = res.AsyncWaitHandle.WaitOne(1000);
       if (isEnd)
       {
           a.EndInvoke(res);
           Console.WriteLine(" !");
       }

       Console.WriteLine("main");
        Console.ReadKey();




    }


    public static void Show(){

        Console.WriteLine("test"+Thread.CurrentThread.ManagedThreadId);
    }

    public static void show1(object a) {

        Console.WriteLine(" "+a+Thread.CurrentThread.ManagedThreadId);
    }


    
}

···