class1.cs
来自「这是.net2005学习不可缺少的教程」· CS 代码 · 共 58 行
CS
58 行
using System;
using System.Threading;
namespace StopThread
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
static int i=0;
static bool state;
static void Main(string[] args)
{
Thread t=new Thread(new ThreadStart(a));
t.Start();
state=true;
Thread t2 = new Thread(new ThreadStart(b));
t2.Start();
//state = true;
while(t.IsAlive)
{
if(i>=50)
{
StopT();
}
}
Console.ReadLine();
}
static void a()
{
while(state)
{
Console.WriteLine(++i);
Thread.Sleep(10);
}
Console.WriteLine("Thread Final");
}
static void b()
{
while (state)
{
Console.WriteLine(++i);
Thread.Sleep(10);
}
Console.WriteLine("Thread Final");
}
static void StopT()
{
state=false;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?