C#多线程Thread基础
				
									
					
					
						|  | 
							admin 2025年3月29日 19:42
								本文热度 1472 | 
					
				 
				Thread 类用于创建和管理线程,表示托管线程,每个Thread对象都表示一个托管线程,每个托管线程都会对对应一个函数。线程:操作系统为了提高效率将一个进程分为多个线程。使用Thread开启两个线程同时运行。按下执行任务按钮后,两个任务同时执行,互不影响。namespace _012_多线程Thread基础{    public partial class Thread基础 : Form    {        public Thread基础()        {            InitializeComponent();        }               private void btTask1_Click(object sender, EventArgs e)        {                                 Thread thread1 = new Thread(()=>            {                for (int i = 0; i < 10; i++)                {                    Console.WriteLine((10 + i) + "  ");                    Thread.Sleep(1000);                }            });            thread1.IsBackground = true;            thread1.Start();        }        private void btTask2_Click(object sender, EventArgs e)        {                        Thread thread2 = new Thread(() =>            {                for (int i = 0; i < 10; i++)                {                    Console.WriteLine((100 + i) + "  ");                    Thread.Sleep(1000);                }            });            thread2.IsBackground = true;            thread2.Start();        }    }}
阅读原文:原文链接
该文章在 2025/3/31 11:26:12 编辑过