1. 无返回值
方法1
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Start:" + DateTime.Now);
Task task = new Task(() => Test());
task.Start();
Task task1 = new Task(() => Test1());
task1.Start();
Console.ReadKey();
}
public static void Test()
{
Thread.Sleep(2000);
Console.WriteLine("Test:" + DateTime.Now);
}
public static void Test1()
{
Thread.Sleep(2000);
Console.WriteLine("Test1:" + DateTime.Now);
}
}
运行结果
———————————————————————————————————————
方法2
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Start:" + DateTime.Now);
Task.Run(() => Test());
Task.Run(() => {
Test1();
});
Console.Rea