当前位置:网站首页>了解下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");
// 计数到 10
for (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();
}
}
}
边栏推荐
- 如何建立私域流量?私域流量对企业有什么好处?
- EPSANet: An Efficient Pyramid Split Attention Block on Convolutional Neural Network
- mysqldump --set-gtid-purged=OFF
- Database triggers and transactions
- Biotin-EDA|CAS:111790-37-5| 乙二胺生物素
- Redis分布式锁
- 【论文阅读】Distilling the Knowledge in a Neural Network
- Codeforces Round #811 (Div. 3)无DF
- prometheus监控mysql_galera集群
- JSP中page指令的import命令具有什么功能呢?
猜你喜欢
随机推荐
EPSANet: An Efficient Pyramid Split Attention Block on Convolutional Neural Network
Write a small game in C (three chess)
Biotin-LC-Hydrazide|CAS:109276-34-8|生物素-LC-酰肼
[OC学习笔记]ARC与引用计数
Seleniu screenshots code and assign name to the picture
Biotinyl Cystamine | CAS: 128915-82-2 | biotin cysteamine
HCIP笔记第十三天
查看变量的数据格式
Business Intelligence Platform BI Business Intelligence Analysis Platform How to Choose the Right Business Intelligence Platform BI
【C】关于柔性数组.简要的谈谈柔性数组
力扣:第 304 场周赛
解决IDEA安装安装插件慢问题
MySQL 中 count() 和 count(1) 有什么区别?哪个性能最好?
Ansible 学习总结(11)—— task 并行执行之 forks 与 serial 参数详解
pycharm的基本使用教程(1)
R语言plotly可视化:plotly可视化回归模型实际值和回归预测值的散点图分析回归模型的预测效能、一个好的模型大部分的散点在对角线附近(predicted vs actual)
Biotin-EDA|CAS:111790-37-5| Ethylenediamine biotin
BGP solves routing black hole through MPLS
Flink 监控指南 被动拉取 Rest API
HCIP笔记十六天