异步线程:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; //添加引用 using System.Threading; namespace ConsoleApp2 { class Program { //异步线程 static void Main(string[] args) { //第一个线程 Thread thread1 = new Thread(()=> { for (int i = 0; i < 10; i++) { Console.WriteLine(i); Thread.Sleep(1000); } }); thread1.IsBackground = true; thread1.Start(); //第二个线程 Thread thread2 = new Thread(()=> { for (int i = 10; i < 20; i++) { Console.WriteLine(i); Thread.Sleep(1000); } }); //设置为后台线程,应用关闭后台线程就关闭 thread2.IsBackground = true; thread2.Start(); Console.ReadLine(); } } }