当前位置:网站首页>了解下C# 多线程
了解下C# 多线程
2022-08-02 08:17:00 【nginx】
using System;using System.Threading;namespace MultithreadingApplication{class ThreadCreationProgram{public static void CallToChildThread(){try{Console.WriteLine("Child thread starts");// 计数到 10for (int counter = 0; counter <= 10; counter++){Thread.Sleep(500);Console.WriteLine(counter);}Console.WriteLine("Child Thread Completed");}catch (ThreadAbortException e){Console.WriteLine("Thread Abort Exception");}finally{Console.WriteLine("Couldn't catch the Thread Exception");}}static void Main(string[] args){ThreadStart childref = new ThreadStart(CallToChildThread);Console.WriteLine("In Main: Creating the Child thread");Thread childThread = new Thread(childref);childThread.Start();// 停止主线程一段时间Thread.Sleep(2000);// 现在中止子线程Console.WriteLine("In Main: Aborting the Child thread");childThread.Abort();Console.ReadKey();}}}
边栏推荐
猜你喜欢

Redis分布式锁入门

(Note) AXIS ACASIS DT-3608 Dual-bay Hard Disk Array Box RAID Setting

mysql 中 in 的用法

类和对象【下】

Biotin-EDA|CAS:111790-37-5| 乙二胺生物素

Button to control the running water light (timer)

Biotin-EDA|CAS:111790-37-5| Ethylenediamine biotin

How to use postman

OneNote 教程,如何在 OneNote 中创建更多空间?

CASA模型、CENTURY模型应用与案例分析
随机推荐
Biotin-C6-amine|N-生物素基-1,6-己二胺|CAS:65953-56-2
BGP通过MPLS解决路由黑洞
Elasticserch 自定义字段,用户会频繁的创建和删除字段,怎么设计mapping?
王学岗-编译出运行的文件
etcd implements large-scale service governance application combat
Biotin hydrazide HCl|CAS:66640-86-6|Biotin-hydrazide hydrochloride
[OC学习笔记]weak的实现原理
PostgreSQL learning summary (11) - PostgreSQL commonly used high-availability cluster solutions
C语言_指针
Flink 系统性学习笔记系列
如何做好项目管理
为什么都推荐使用wordpress, 而不是 phpcms 这些国内的CMS呢?
JSP页面中page指令contentPage/pageEncoding具有什么功能呢?
[OC学习笔记]ARC与引用计数
Installation and use of pnpm
QT web development - Notes - 3
近期在SLAM建图和定位方面的进展
小说里的编程 【连载之二十二】元宇宙里月亮弯弯
Database Plus 的云上之旅:SphereEx 正式开源 ShardingSphere on Cloud 解决方案
Database triggers and transactions