.Net Core 1.0 Thread类没有Interrupt()函数

时间:2017-01-20 12:30:29

标签: c# multithreading .net-core

通过阅读msdn上的文档,我只想尝试一些线程类函数。但是发现这个奇怪的行为在Thread Class中没有中断函数。我正在使用Visual Studio 2015和.net core 1.0控制台应用程序

using System;
using System.Threading;
namespace ThreadingBasicsRight
{

public class Program
{
    public static Object _lock = new Object();
    public static void Main(string[] args)
    {
        Thread t = new Thread(test1);
        t.Start();
        t.Interrupt(); 
    }
    public static void test1()
    {
        lock (_lock)
        {
            for (int i = 0; i < 1000; i++)
            {
                Console.WriteLine(i);
            }
            Thread.Sleep(100);
        }
    }
    public static void test2()
    {
        lock (_lock)
        {
            Console.WriteLine("process is not in a dead lock");
        }
    }
 }
}

0 个答案:

没有答案