unity游戏开发-C#语言基础篇(多线程)

···
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);
    }


    
}

···

你可能感兴趣的:(unity游戏开发-C#语言基础篇(多线程))