国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

C# 多線程操作樣例

2019-11-17 02:24:59
字體:
來源:轉載
供稿:網友
C# 多線程操作樣例

using System;using System.Threading; //引用多線程namespace ThreadTest{    public class Alpha    {        public void Beta()        {            while (true)            {                Console.WriteLine("Alpha.Beta is running in its own thread.");            }        }    };    public class Simple    {        public static int Main()        {            Console.WriteLine("Thread Start/Stop/Join Sample");            Alpha oAlpha = new Alpha();        //file://這里創建一個線程,使之執行Alpha類的Beta()方法            Thread oThread = new Thread(new ThreadStart(oAlpha.Beta));            oThread.Start();            while (!oThread.IsAlive)                Thread.Sleep(1);            oThread.Abort();            oThread.Join();            Console.WriteLine();            Console.WriteLine("Alpha.Beta has finished");            try            {                Console.WriteLine("Try to restart the Alpha.Beta thread");                oThread.Start();            }            catch (ThreadStateException)            {                Console.Write("ThreadStateException trying to restart Alpha.Beta. ");                Console.WriteLine("Expected since aborted threads cannot be restarted.");                Console.ReadLine();            }            return 0;        }    }}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 丘北县| 阿城市| 衢州市| 和林格尔县| 老河口市| 绥棱县| 富阳市| 洞头县| 紫阳县| 清原| 枝江市| 都江堰市| 绥棱县| 镇康县| 金溪县| 滦平县| 平凉市| 兴隆县| 平遥县| 会昌县| 天柱县| 茶陵县| 武隆县| 郯城县| 固安县| 航空| 芷江| 汶川县| 定南县| 呼伦贝尔市| 阿拉善右旗| 安宁市| 徐州市| 康马县| 西乌珠穆沁旗| 长泰县| 千阳县| 佳木斯市| 泰顺县| 治多县| 抚州市|