Ejemplo n.º 1
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="initialState"></param>
 /// <param name="mode"></param>
 public EventWaitHandleEx(bool initialState, EventResetMode mode)
 {
     if (mode == EventResetMode.AutoReset)
     {
         this._eventWaitHandle = new AutoResetEvent(initialState);
     }
     else if (mode == EventResetMode.ManualReset)
     {
         this._eventWaitHandle = new ManualResetEvent(initialState);
     }
     else
     {
         throw new NotImplementedException(mode.ToString());
     }
 }
Ejemplo n.º 2
0
        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();
                        }
                    }
        }
Ejemplo n.º 3
0
        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();
                }
            }
        }