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

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

C#線程調(diào)用

2019-11-17 03:01:37
字體:
供稿:網(wǎng)友

C#線程調(diào)用

一.線程的優(yōu)點(diǎn)

1.服務(wù)器一般負(fù)載的情況下線程可以提高效率;

2.使用線程執(zhí)行的代碼出現(xiàn)故障不會(huì)影響主程序,提高程序穩(wěn)定和可靠性。

二.線程的創(chuàng)建及其常用屬性

1.線程創(chuàng)建

ThreadStartts1=newThreadStart(function2);//線程定義執(zhí)行

Threadt1=newThread(ts1);

t1.Start();

或者

Threadt1=newThread(newThreadStart(function2));

t1.Start();

2.線程常用屬性

PRiority獲取或設(shè)置,線程優(yōu)先級

IsBackgroud獲取或設(shè)置,是否為后臺線程

Abort():終止線程

Start()開始線程

三.程序?qū)嵗?/strong>

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;namespace Thread2{ class Program { static void function1() { for (int i = 0; i < 40; i++) { Console.WriteLine(i); } } static void function2() { for (int i = 41; i <200; i++) { Console.WriteLine(i); int c = 2; int x = 0; int y = c / x; } } static void function3() { for (int i = 200; i < 205; i++) { Console.WriteLine(i); //int c = 2; //int x = 0; //int y = c / x; } } static void Main(string[] args) { Console.WriteLine("Main begin !"); ThreadStart ts = new ThreadStart(function1);//線程定義 執(zhí)行 Thread t = new Thread(ts); t.Priority = ThreadPriority.Highest; t.Start(); Console.WriteLine("Main end!"); ThreadStart ts1 = new ThreadStart(function2);//線程定義 執(zhí)行 Thread t1 = new Thread(ts1); //t1.Priority = ThreadPriority.Highest; //t1.IsBackground = true;//沒執(zhí)行完 主程序也退出 t1.Start(); function3();//直接執(zhí)行 Console.WriteLine("Main1111 end!"); } }}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 蒲江县| 保康县| 闽清县| 竹北市| 乌兰县| 惠东县| 祥云县| 绥德县| 台北县| 隆子县| 陆河县| 沂源县| 原阳县| 怀安县| 九龙县| 和政县| 西贡区| 巴楚县| 阳朔县| 太仓市| 泰来县| 昌都县| 南投县| 泊头市| 临高县| 饶河县| 绍兴县| 宜兰市| 岳阳市| 长丰县| 唐海县| 观塘区| 独山县| 晴隆县| 怀集县| 阳曲县| 若尔盖县| 即墨市| 寻甸| 麻江县| 铜川市|