如何在C#中创建线程?
线程是轻量级进程。线程被定义为程序的执行路径。通过扩展Thread类来创建线程。然后,扩展的Thread类将调用该Start()方法以开始执行子线程。
线程示例:线程使用的一个常见示例是现代操作系统对并发编程的实现。使用线程可以节省CPU周期,并提高应用程序的效率。
以下是显示如何创建线程的示例。
示例
using System;
using System.Threading;
namespace Demo {
class Program {
public static void ThreadFunc() {
Console.WriteLine("Child thread starts");
}
static void Main(string[] args) {
ThreadStart childref = new ThreadStart(ThreadFunc);
Console.WriteLine("In Main: Creating the Child thread");
Thread childThread = new Thread(childref);
childThread.Start();
Console.ReadKey();
}
}
}输出结果
In Main: Creating the Child thread Child thread starts
热门推荐
2 训练狗狗成为
3 训练狗狗几岁
4 反应训练狗狗
5 听力训练狗狗
7 狗狗尿训练
8 拳击训练狗狗
10 狗狗训练卧室
11 一个月狗狗怎么训练
12 几个月训练狗狗大小便
13 牧羊犬训练狗狗
14 狗狗训练做
15 狗狗训练它
16 可以训练狗狗
17 训练狗狗给球
18 训练狗狗的技巧