请看题
class Program
{
Thread newThread;
static void Main(string[] args)
{
Program a = new Program();
string threadName = Thread.CurrentThread.Name;
Thread.CurrentThread.Name = "主线程";
threadName = Thread.CurrentThread.Name;
int sum = 0;
a.StartThread();
for (int i = 1; i <= 100; i++)
{
sum += i;
Console.WriteLine("线程:{2},i = {0},sum = {1}", i, sum, threadName);
}
Console.ReadKey();
}
public void StartThread()
{
ThreadStart myThreadStart = new ThreadStart(print);
newThread = new Thread(myThreadStart);
newThread.Name = "My new Thread";
newThread.Start();
}
public void print()
{
int sum = 0;
try
{
for (int i = 1; i <= 100; i++)
{
sum += i;
Console.WriteLine("线程:{2},i = {0},sum = {1}", i, sum, Thread.CurrentThread.Name);
if (i == 50)
{
newThread.Interrupt();
}
}
}
catch (ThreadInterruptedException)
{
Console.WriteLine("My new thread现在i加到了50,被中断");
}
}
}
为什么newTread.Interrupt(),是断不了