1.代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApp5
{
class Program
{
public static int num = 0;
static void Main(string[] args)
{
var t1 = new Task(fun);
t1.Start();
var t2 = new Task(fun);
t2.Start();
t1.Wait();
t2.Wait();
System.Console.WriteLine(num);
System.Console.WriteLine("hello word");
System.Console.ReadKey();
}
public static void fun() {
for (int i = 0; i < 10; i++) {
Thread.Sleep(10);
num++;
}
}
}
}
2.运行结果