简体   繁体   中英

.NET Core 2.1 EventWaitHandle Not Supported?

I'm converting a C# .NET Framework project over to .NET Core. It compiles without errors or warnings and runs fine on Windows, but when I try it on CentOS 7, I get a System.PlatformNotSupportedException when I try to create an instance of EventWaitHandle. Here is the code:

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

There is clearly .NET Core 2.1 support for this class as there is MS documentation for it here:

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

Is this as simple as the error describes and this class is not supported across multiple platforms? If so, why is it included in .NET Core? Could there be anything else at play here?

If it is simply not supported, is there an alternative class that someone can suggest that is supported completely in .NET Core 2.1?

Thanks.

.Net Core has some platform specific apis. This is one of them. It is the named handles it can't handle, see the 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
        }

        ...

Some more interesting reads 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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