namespace demo1027线程 { internal class Program { static void Main(string[] args) { Console.BufferWidth = 400;//控制台窗口的宽度 Console.BufferHeight = 400;//控制台窗口的高度
/*//Thread线程类
while (true)
{
Thread.Sleep(1000);
Console.WriteLine("hhh");
}*/
Thread newThread = new Thread(newThreadLogic);
//开启线程
newThread.Start();
//将新线程申明为后台线程 当我们 的主线程结束运行会强制关闭其他线程
newThread.IsBackground = true;
Console.WriteLine("6666");
Console.WriteLine("6666");
Console.WriteLine("6666");
//按键判断 按下一个按键才会执行下一个代码
Console.ReadKey();
Console.WriteLine(Console.ReadKey().Key == ConsoleKey.UpArrow);//可以捕获到按键
Console.WriteLine("6666");
// Console.BackgroundColor = ConsoleColor.DarkRed;
/*Console.ForegroundColor = ConsoleColor.DarkRed;
int x = 0;
int y = 0;
Console.SetCursorPosition(x, y);//x轴走两步等于y轴走一步
Console.Write("■");
Console.CursorVisible = false;
while (true)
{
Thread.Sleep(1000);
Console.Clear();
x += 2;
y += 1;
Console.SetCursorPosition(x, y);
Console.Write("■");
}
//让方块一直往前移动*/
}
public static void newThreadLogic()
{
int exp = 0;
while (false)
{
//Thread.Sleep(1000);
exp += 1;
Console.WriteLine($"经验值+1,当前经验值为{exp}");
}
}
}
}