C#多线程编程实战1.1创建线程
程序员文章站
2022-04-28 09:10:46
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;using System.Threading.Tasks;//创建线程//两组范围为1-1 ......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
//创建线程
//两组范围为1-10的数字会随机交叉输出,说明PrintNumbers方法同时运行在主线程和另一个线程中
namespace Recipe1
{
class Program
{
static void Main(string[] args)
{
Thread th = new Thread(PrintNumbers);
th.Start();
PrintNumbers();
Console.ReadKey();
}
static void PrintNumbers()
{
Console.WriteLine("Starting");
for (int i = 1; i < 10; i++)
{
Console.WriteLine(i);
}
}
}
}
下一篇: jquery事件之浏览器模型解析