繁体   English   中英

Mac上的.NET Core中的Thread.Sleep()

[英]Thread.Sleep() in .NET Core on Mac

我在Mac机器上使用.NET Core。

我的代码中的某个地方我想使用这段代码:

System.Threading.Thread.Sleep(100);

但它无法在System.Threading命名空间中找到Thread

怎么了? 是不是Thread可用于Mac,或者我错过了什么?

你有没有将System.Threading.Thread包添加到你的project.json

{
    "version": "1.0.0-*",
    "compilationOptions": {
        "emitEntryPoint": true
    },

    "dependencies": {
        "NETStandard.Library": "1.0.0-rc2-23811",
        "System.Threading.Thread": "4.0.0-beta-23516"
    },

    "frameworks": {
        "dnxcore50": { }
    }
}

然后我可以使用Thread.Sleep

using System;
using System.Threading;


    namespace ConsoleApplication
    {
        public class Program
        {
            public static void Main(string[] args)
            {
                Console.WriteLine(DateTime.Now);
                Thread.Sleep(2000);
                Console.WriteLine("Hello World!");
                Console.WriteLine(DateTime.Now);
            }
        }
    }

在此输入图像描述

Mac不支持Thread吗?

还没有: https//github.com/dotnet/corefx/issues/2576

当前的System.Threading.Thread(和System.Threading.ThreadPool)包仅支持桌面和CoreCLR。

并且: https//github.com/dotnet/corefx/issues/2576#issuecomment-187184341

我可以看到dotnet-core NuGet feed中最新的System.Threading.Thread包没有改变这张图片。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM