当前位置: 首页>>代码示例>>C#>>正文


C# SafeWaitHandle.SetHandleAsInvalid方法代码示例

本文整理汇总了C#中Microsoft.Win32.SafeHandles.SafeWaitHandle.SetHandleAsInvalid方法的典型用法代码示例。如果您正苦于以下问题:C# SafeWaitHandle.SetHandleAsInvalid方法的具体用法?C# SafeWaitHandle.SetHandleAsInvalid怎么用?C# SafeWaitHandle.SetHandleAsInvalid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Win32.SafeHandles.SafeWaitHandle的用法示例。


在下文中一共展示了SafeWaitHandle.SetHandleAsInvalid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EventWaitHandle

        public EventWaitHandle(bool initialState, EventResetMode mode, string name)
        {
            if (null != name)
            {
                if (((int)Interop.Constants.MaxPath) < name.Length)
                {
                    throw new ArgumentException(SR.Format(SR.Argument_WaitHandleNameTooLong, name));
                }
            }
            Contract.EndContractBlock();

            uint eventFlags = initialState ? (uint)Interop.Constants.CreateEventInitialSet : 0;

            IntPtr unsafeHandle;
            switch (mode)
            {
                case EventResetMode.ManualReset:
                    eventFlags |= (uint)Interop.Constants.CreateEventManualReset;
                    break;

                case EventResetMode.AutoReset:
                    break;

                default:
                    throw new ArgumentException(SR.Format(SR.Argument_InvalidFlag, name));
            };

            unsafeHandle = Interop.mincore.CreateEventEx(IntPtr.Zero, name, eventFlags, (uint)Interop.Constants.EventAllAccess);
            int errorCode = (int)Interop.mincore.GetLastError();
            SafeWaitHandle _handle = new SafeWaitHandle(unsafeHandle, true);

            if (_handle.IsInvalid)
            {
                _handle.SetHandleAsInvalid();
                if (null != name && 0 != name.Length && Interop.mincore.Errors.ERROR_INVALID_HANDLE == errorCode)
                    throw new WaitHandleCannotBeOpenedException(SR.Format(SR.Threading_WaitHandleCannotBeOpenedException_InvalidHandle, name));

                throw ExceptionFromCreationError(errorCode, name);
            }
            SafeWaitHandle = _handle;
        }
开发者ID:tijoytom,项目名称:corert,代码行数:41,代码来源:EventWaitHandle.cs

示例2: EventWaitHandle

        public EventWaitHandle(bool initialState, EventResetMode mode, string name)
        {
            if(null != name && System.IO.Path.MAX_PATH < name.Length)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong",name));
            }
            Contract.EndContractBlock();
            
            SafeWaitHandle _handle = null;
#if MONO
            int errorCode;
#endif
            switch(mode)
            {
                case EventResetMode.ManualReset:
#if MONO
                    _handle = new SafeWaitHandle (NativeEventCalls.CreateEvent_internal (true, initialState, name, out errorCode), true);
#else
                    _handle = Win32Native.CreateEvent(null, true, initialState, name);
#endif
                    break;
                case EventResetMode.AutoReset:
#if MONO
                    _handle = new SafeWaitHandle (NativeEventCalls.CreateEvent_internal (false, initialState, name, out errorCode), true);
#else
                    _handle = Win32Native.CreateEvent(null, false, initialState, name);
#endif
                    break;

                default:
                    throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag",name));
            };
                
            if (_handle.IsInvalid)
            {
#if !MONO
                int errorCode = Marshal.GetLastWin32Error();
#endif
            
                _handle.SetHandleAsInvalid();
                if(null != name && 0 != name.Length && Win32Native.ERROR_INVALID_HANDLE == errorCode)
                    throw new WaitHandleCannotBeOpenedException(Environment.GetResourceString("Threading.WaitHandleCannotBeOpenedException_InvalidHandle",name));

                __Error.WinIOError(errorCode, name);
            }
            SetHandleInternal(_handle);
        }
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:47,代码来源:eventwaithandle.cs


注:本文中的Microsoft.Win32.SafeHandles.SafeWaitHandle.SetHandleAsInvalid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。