【随堂笔记】unity中socket用法(三,服务器端线程的使用)

手机项目,最好不要使用线程,因为unity专门提供了协程,枝线程不能访问主线程(ui)
手机使用线程,容易导致硬件出问题

线程测试代码

/// <summary>
        /// 线程的测试方法
        /// </summary>
        public static void TreadTest()
        {
            int count = 0;
            while (count<100)
            {
                Console.WriteLine("我执行了"+count+"次");
                //休息时间间隔,单位毫秒
                Thread.Sleep(100);
                count++;
            }
            Console.WriteLine("线程已关闭");
        }

        static void Main(string[] args)
        {
            //定义线程
            Thread thread = new Thread(TreadTest);
            //开启线程
            thread.Start();
            //停止线程
            //thread.Abort();

运行结果如下
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_42661974/article/details/84314853