using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
class Program
{
static void Main(string[] args)
{
// 获取当前程序的所有线程
ProcessThreadCollection threadCollection = Process.GetCurrentProcess().Threads;
Console.WriteLine("现在线程数字:" + threadCollection.Count);
Thread t =new Thread(DownLoadFile_My);//创建了线程还未开启
t.Start();//用来给函数传递参数,开启线程
void DownLoadFile_My() {
Console.WriteLine("DownLoadFile_My 。。");
}
threadCollection = Process.GetCurrentProcess().Threads;
Console.WriteLine("现在线程数字:"+threadCollection.Count);
Console.ReadKey();
}
}
这段代码完整展示了,当系统启动默认有多少个线程,以及启动一个新的线程之后,系统线程的计数,我使用vs2022,dubug状态默认情况是有15个线程,非debug情况,默认是13个线程