110,539
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Thread th = new Thread(Test1);
th.Start();
Thread th1 = new Thread(Test2);
th1.Start();
Console.ReadKey();
}
static void Test1()
{
int count = 0;
while (true)
{
count++;
//Console.WriteLine("线程1:{0}", count);
Thread.Sleep(100);
}
}
static void Test2()
{
int count = 0;
while (true)
{
count++;
Console.WriteLine("线程2:{0}",count);
Thread.Sleep(100);
}
}
}
}
在Test1的while循环下一个断点 然后看下控制台输出 线程2 计数
之后把断点下了点继续,你会发现计数没有跳跃比如原来100 一下跳到130 而是接着从101开始
像这种问题 自己用代码调一下 一下就记住了 比别人说管用多了