c# - .NET Core 2.1 不支持 EventWaitHandle?

标签 c# .net-core

我正在将 C# .NET Framework 项目转换为 .NET Core。它编译时没有错误或警告,并且在 Windows 上运行良好,但是当我在 CentOS 7 上尝试它时,当我尝试创建 EventWaitHandle 的实例时,我得到了 System.PlatformNotSupportedException。这是代码:

this.eventHandle = new EventWaitHandle(initialState, resetMode, name);

显然 .NET Core 2.1 支持此类,因为这里有它的 MS 文档:

https://learn.microsoft.com/en-us/dotnet/api/system.threading.eventwaithandle.-ctor?view=netcore-2.1

这是否像错误描述的那样简单,并且此类不支持跨多个平台?如果是这样,为什么它包含在 .NET Core 中?难道还有其他事情在起作用吗?

如果它根本不受支持,是否有人可以建议在 .NET Core 2.1 中完全支持的替代类?

谢谢。

最佳答案

.Net Core 有一些特定于平台的 api。这是其中之一。这是它无法处理的命名句柄,请参阅 source

    public EventWaitHandle(bool initialState, EventResetMode mode, string name)
    {
        if(name != null)
        {
#if PLATFORM_UNIX
            throw new PlatformNotSupportedException(Environment.GetResourceString("PlatformNotSupported_NamedSynchronizationPrimitives"));
#else
            if (System.IO.Path.MaxPath < name.Length)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", name));
            }
#endif
        }

        ...

一些更有趣的读物 here :

I'm uncertain what .NET technology you should be using instead. If you don't require cross-process synchronization, you don't need to specify a name for EventWaitHandle, or you can use a different subclass of EventWaitHandle, such as ManualResetEvent or AutoResetEvent.

关于c# - .NET Core 2.1 不支持 EventWaitHandle?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53526755/

相关文章:

c# - Linq to Objects DateTime 除了忽略时间

c# - XML 解析和转换(XSLT 或其他)

c# - 在下拉列表中设置从 2012/11/01 到 2012 年 11 月的日期格式 C#

asp.net-core - 我如何知道 Linux 中是否安装了 ASP.NET Core?

asp.net-core - 修复 "Package xxx is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0)"

c# - dotnetcore GetTypeInfo() 没有在类型对象的变量上定义?

c# - 以编程方式获取 dotnet 核心运行时的当前运行版本

c# - 更好的解决方案,允许 C# 中的泛型类型使用 MinValue 和 MaxValue 字段

c# - 使用 xUnit 和 asp.net core 测试我的服务

c# - DotNetBrowser DOMNode调试