【隨堂筆記】unity中socket用法(三,伺服器端執行緒的使用)
阿新 • • 發佈:2018-11-21
手機專案,最好不要使用執行緒,因為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();
執行結果如下