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


C# EventResetMode类代码示例

本文整理汇总了C#中EventResetMode的典型用法代码示例。如果您正苦于以下问题:C# EventResetMode类的具体用法?C# EventResetMode怎么用?C# EventResetMode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: 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;
            switch(mode)
            {
                case EventResetMode.ManualReset:
                    _handle = Win32Native.CreateEvent(null, true, initialState, name);
                    break;
                case EventResetMode.AutoReset:
                    _handle = Win32Native.CreateEvent(null, false, initialState, name);
                    break;

                default:
                    throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag",name));
            };
                
            if (_handle.IsInvalid)
            {
                int errorCode = Marshal.GetLastWin32Error();
            
                _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:iskiselev,项目名称:JSIL.NetFramework,代码行数:34,代码来源:eventwaithandle.cs

示例2: IsManualReset

		private static bool IsManualReset (EventResetMode mode)
		{
			if ((mode < EventResetMode.AutoReset) || (mode > EventResetMode.ManualReset)) {
				throw new ArgumentException ("mode");
			}
			return mode == EventResetMode.ManualReset;
		}
开发者ID:duarten,项目名称:mono,代码行数:7,代码来源:EventWaitHandle.cs

示例3: EventWaitHandle

        public EventWaitHandle(bool initialState, EventResetMode mode, string name)
        {
            if ((name != null) && (260 < name.Length))
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", new object[] { name }));
            }
            SafeWaitHandle handle = null;
            switch (mode)
            {
                case EventResetMode.AutoReset:
                    handle = Win32Native.CreateEvent(null, false, initialState, name);
                    break;

                case EventResetMode.ManualReset:
                    handle = Win32Native.CreateEvent(null, true, initialState, name);
                    break;

                default:
                    throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag", new object[] { name }));
            }
            if (handle.IsInvalid)
            {
                int errorCode = Marshal.GetLastWin32Error();
                handle.SetHandleAsInvalid();
                if (((name != null) && (name.Length != 0)) && (6 == errorCode))
                {
                    throw new WaitHandleCannotBeOpenedException(Environment.GetResourceString("Threading.WaitHandleCannotBeOpenedException_InvalidHandle", new object[] { name }));
                }
                __Error.WinIOError(errorCode, "");
            }
            base.SetHandleInternal(handle);
        }
开发者ID:randomize,项目名称:VimConfig,代码行数:32,代码来源:EventWaitHandle.cs

示例4: EventWaitHandle

		public EventWaitHandle (bool initialState, EventResetMode mode,
					string name, out bool createdNew,
					EventWaitHandleSecurity eventSecurity)
		{
			bool manual = IsManualReset (mode);
			Handle = NativeEventCalls.CreateEvent_internal (manual, initialState, name, out createdNew);
		}
开发者ID:nicolas-raoul,项目名称:mono,代码行数:7,代码来源:EventWaitHandle.cs

示例5: EventWaitHandle

 public EventWaitHandle(bool initialState, EventResetMode mode, string name, out bool createdNew)
 {
     IntPtr ptr = CreateEvent(IntPtr.Zero, mode == EventResetMode.ManualReset, initialState, name);
     if (ptr.Equals(IntPtr.Zero))
     {
         throw new ApplicationException("Cannot create " + name);
     }
     createdNew = Marshal.GetLastWin32Error() != 0xb7;
     Handle = ptr;
 }
开发者ID:slay22,项目名称:TrainstationAdvisor,代码行数:10,代码来源:EventWaitHandle.cs

示例6: OpenOrCreate

        /// <summary>
        /// Close any open handles with <paramref name="name"/> and open a new one.
        /// </summary>
        /// <param name="name">The handle name.</param>
        /// <param name="initialState">Initial state.</param>
        /// <param name="mode">The mode.</param>
        /// <returns>The new EventWaitHandle created.</returns>
        public static EventWaitHandle OpenOrCreate(string name, bool initialState, EventResetMode mode)
        {
            try
            {
                EventWaitHandle.OpenExisting(name).Close();
            }
            catch (WaitHandleCannotBeOpenedException) { }

            return new EventWaitHandle(initialState, mode, name);
        }
开发者ID:juanplopes,项目名称:simple,代码行数:17,代码来源:NamedEvents.cs

示例7: EventEx

        /// <summary>
        /// Default Constructor
        /// </summary>
        /// <param name="eventName">name of the event to distinguish</param>
        public EventEx(String eventName = null)
            : base()
        {
            m_eventResetMode=EventResetMode.AutoReset;
	        m_isInitialRaised=true;
            m_name=eventName;
            if (m_name == null)
                m_event = new EventWaitHandle(m_isInitialRaised, m_eventResetMode);
            else
                m_event = new EventWaitHandle(m_isInitialRaised, m_eventResetMode, m_name);
        }
开发者ID:tangyiyong,项目名称:EpLibrary.cs,代码行数:15,代码来源:EventEx.cs

示例8: EventWaitHandleEx

        public EventWaitHandleEx(bool initialState, EventResetMode mode, string name, out bool createdNew)
        {
            var handle = NativeMethods.CreateEvent(IntPtr.Zero, mode == EventResetMode.ManualReset, initialState, name);
            if (handle == IntPtr.Zero)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            createdNew = Marshal.GetLastWin32Error() != ERROR_ALREADY_EXISTS;

            Handle = handle;
        }
开发者ID:usausa,项目名称:Smart-Net-CE,代码行数:12,代码来源:EventWaitHandleEx.cs

示例9: EventEx

        /// <summary>
        /// Default Constructor
        /// </summary>
        /// <param name="eventName">name of the event to distinguish</param>
        public EventEx()
            : base()
        {
            m_eventResetMode = EventResetMode.AutoReset;
	        m_isInitialRaised=true;
            if (m_eventResetMode == EventResetMode.AutoReset)
                m_event = new AutoResetEvent(m_isInitialRaised);
            else
            {
                m_event = new ManualResetEvent(m_isInitialRaised);
            }
        }
开发者ID:tangyiyong,项目名称:EpLibrary.cs,代码行数:16,代码来源:EventEx.cs

示例10: Create

        public static bool Create(string name, EventResetMode mode, out EventWaitHandle signal)
        {
            var users = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null);
            var rule = new EventWaitHandleAccessRule(users, EventWaitHandleRights.Synchronize |
            EventWaitHandleRights.Modify, AccessControlType.Allow);
            var security = new EventWaitHandleSecurity();
            security.AddAccessRule(rule);

            bool created;
            signal = new EventWaitHandle(false, mode, @"Global\" + name, out created, security);

            return created;
        }
开发者ID:JackFong,项目名称:ServiceStarter,代码行数:13,代码来源:EventWaitHandleHelper.cs

示例11: Ctor_StateModeNameCreatedNew_Windows

 public void Ctor_StateModeNameCreatedNew_Windows(bool initialState, EventResetMode mode)
 {
     string name = Guid.NewGuid().ToString("N");
     bool createdNew;
     using (var ewh = new EventWaitHandle(false, EventResetMode.AutoReset, name, out createdNew))
     {
         Assert.True(createdNew);
         using (new EventWaitHandle(false, EventResetMode.AutoReset, name, out createdNew))
         {
             Assert.False(createdNew);
         }
     }
 }
开发者ID:kkurni,项目名称:corefx,代码行数:13,代码来源:EventWaitHandleTests.cs

示例12: 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

示例13: PingPong

        public void PingPong(EventResetMode mode)
        {
            // Create names for the two events
            string outboundName = Guid.NewGuid().ToString("N");
            string inboundName = Guid.NewGuid().ToString("N");

            // Create the two events and the other process with which to synchronize
            using (var inbound = new EventWaitHandle(true, mode, inboundName))
            using (var outbound = new EventWaitHandle(false, mode, outboundName))
            using (var remote = RemoteInvoke(PingPong_OtherProcess, mode.ToString(), outboundName, inboundName))
            {
                // Repeatedly wait for one event and then set the other
                for (int i = 0; i < 10; i++)
                {
                    Assert.True(inbound.WaitOne(FailWaitTimeoutMilliseconds));
                    if (mode == EventResetMode.ManualReset)
                    {
                        inbound.Reset();
                    }
                    outbound.Set();
                }
            }
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:23,代码来源:EventWaitHandleTests.cs

示例14: Ctor_StateMode

 public void Ctor_StateMode(bool initialState, EventResetMode mode)
 {
     using (var ewh = new EventWaitHandle(initialState, mode))
         Assert.Equal(initialState, ewh.WaitOne(0));
 }
开发者ID:kkurni,项目名称:corefx,代码行数:5,代码来源:EventWaitHandleTests.cs

示例15: IsManualReset

		private bool IsManualReset (EventResetMode mode)
		{
			if ((mode < EventResetMode.AutoReset) || (mode > EventResetMode.ManualReset))
				throw new ArgumentException ("mode");
			return (mode == EventResetMode.ManualReset);
		}
开发者ID:robert-j,项目名称:mono-fork,代码行数:6,代码来源:EventWaitHandle.cs


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