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


C# ManualResetEvent.Dispose方法代码示例

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


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

示例1: Socket_ConnectAsyncDnsEndPoint_Success

        public void Socket_ConnectAsyncDnsEndPoint_Success()
        {
            Assert.True(Capability.IPv4Support());

            int port;
            SocketTestServer server = SocketTestServer.SocketTestServerFactory(IPAddress.Loopback, out port);

            SocketAsyncEventArgs args = new SocketAsyncEventArgs();
            args.RemoteEndPoint = new DnsEndPoint("localhost", port);
            args.Completed += OnConnectAsyncCompleted;

            ManualResetEvent complete = new ManualResetEvent(false);
            args.UserToken = complete;

            Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            Assert.True(sock.ConnectAsync(args));

            complete.WaitOne();

            Assert.Equal(SocketError.Success, args.SocketError);
            Assert.Null(args.ConnectByNameError);

            complete.Dispose();
            sock.Dispose();
            server.Dispose();
        }
开发者ID:nbilling,项目名称:corefx,代码行数:26,代码来源:DnsEndPointTest.cs

示例2: WaitOneNonAlertable_disposed_error

        public void WaitOneNonAlertable_disposed_error()
        {
            var e = new ManualResetEvent(true);
            e.Dispose();

            e.WaitOneNonAlertable(10);
        }
开发者ID:tablesmit,项目名称:NRegFreeCom,代码行数:7,代码来源:WindowsWaitHandleExtensionsTests.cs

示例3: StartsElectionAfterElectionTimeout

        public void StartsElectionAfterElectionTimeout()
        {
            // arrange
            var resetEvent = new ManualResetEvent(false);
            var timeout = TimeSpan.FromMilliseconds(100);
            var configMock = new Mock<IServerConfiguration>();
            configMock.Setup(mocked => mocked.ElectionTimeout).Returns(timeout);
            var config = configMock.Object;
            var scheduler = new EventLoop();
            var serverMock = new Mock<IConsensusServerStateApi>();
            serverMock.Setup(mocked => mocked.StartElection()).Callback(() => resetEvent.Set());
            serverMock.Setup(mocked => mocked.Configuration).Returns(config);
            serverMock.Setup(mocked => mocked.Scheduler).Returns(scheduler);
            var server = serverMock.Object;
            var state = new Follower(server);

            // act
            state.Start();
            var changedToCandidate = resetEvent.WaitOne(timeout + timeout);

            // assert
            Assert.That(changedToCandidate, Is.True, "An election timout should have occurred and the state should be changed to candidate");

            // cleanup
            scheduler.Dispose();
            resetEvent.Dispose();
        }
开发者ID:oldslowfatstu,项目名称:NRaft,代码行数:27,代码来源:FollowerTests.cs

示例4: DispatcherThread

        public DispatcherThread()
        {
            startedEvent = new ManualResetEvent(false);
            thread = new Thread(Run);
            thread.SetApartmentState(ApartmentState.STA);
            thread.Name = "DispatcherThread";
            thread.Start();

            startedEvent.WaitOne();
            startedEvent.Dispose();
            startedEvent = null;
        }
开发者ID:Ethan6Lu,项目名称:CefSharp,代码行数:12,代码来源:DispatcherThread.cs

示例5: Socket_ConnectAsyncUnixDomainSocketEndPoint_Success

        public void Socket_ConnectAsyncUnixDomainSocketEndPoint_Success()
        {
            string path = null;
            SocketTestServer server = null;
            UnixDomainSocketEndPoint endPoint = null;

            for (int attempt = 0; attempt < 5; attempt++)
            {
                path = GetRandomNonExistingFilePath();
                endPoint = new UnixDomainSocketEndPoint(path);
                try
                {
                    server = SocketTestServer.SocketTestServerFactory(endPoint, ProtocolType.Unspecified);
                    break;
                }
                catch (SocketException)
                {
                    // Path selection is contingent on a successful Bind(). 
                    // If it fails, the next iteration will try another path.
                }
            }

            try
            {
                Assert.NotNull(server);

                SocketAsyncEventArgs args = new SocketAsyncEventArgs();
                args.RemoteEndPoint = endPoint;
                args.Completed += OnConnectAsyncCompleted;

                ManualResetEvent complete = new ManualResetEvent(false);
                args.UserToken = complete;

                Socket sock = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
                Assert.True(sock.ConnectAsync(args));

                complete.WaitOne();

                Assert.Equal(SocketError.Success, args.SocketError);
                Assert.Null(args.ConnectByNameError);

                complete.Dispose();
                sock.Dispose();
                server.Dispose();
            }
            finally
            {
                File.Delete(path);
            }
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:50,代码来源:UnixDomainSocketTest.cs

示例6: ProcessesCallbacks

        public void ProcessesCallbacks()
        {
            // arrange
            var worker = new EventLoopWorker();
            var workDone = new ManualResetEvent(false);
            workDone.Reset();

            // act
            worker.Schedule(() => workDone.Set());

            // assert
            Assert.That(workDone.WaitOne(TimeSpan.FromMilliseconds(100)), Is.True, "Exepcted work to be done within 100ms");

            // dispose stuff
            worker.Dispose();
            workDone.Dispose();
        }
开发者ID:oldslowfatstu,项目名称:NLoop,代码行数:17,代码来源:EventLoopWorkerTests.cs

示例7: Action

 public override bool Action(string action)
 {
     bool result = base.Action(action);
     if (result && action == ACTION_FILTER)
     {
         using (LogPurgerForm dlg = new LogPurgerForm())
         {
             if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
             {
                 using (Utils.FrameworkDataUpdater upd = new Utils.FrameworkDataUpdater(Core))
                 {
                     _actionReady = new ManualResetEvent(false);
                     Thread thrd = new Thread(new ThreadStart(this.purgeLogsWithFilterThreadMethod));
                     thrd.Start();
                     while (!_actionReady.WaitOne(10))
                     {
                         System.Windows.Forms.Application.DoEvents();
                     }
                     thrd.Join();
                     _actionReady.Dispose();
                     _actionReady = null;
                 }
             }
         }
     }
     else if (result && action == ACTION_QUICKPURGE)
     {
         using (Utils.FrameworkDataUpdater upd = new Utils.FrameworkDataUpdater(Core))
         {
             _actionReady = new ManualResetEvent(false);
             Thread thrd = new Thread(new ThreadStart(this.purgeLogsThreadMethod));
             thrd.Start();
             while (!_actionReady.WaitOne(10))
             {
                 System.Windows.Forms.Application.DoEvents();
             }
             thrd.Join();
             _actionReady.Dispose();
             _actionReady = null;
         }
     }
     return result;
 }
开发者ID:RH-Code,项目名称:GAPP,代码行数:43,代码来源:LogPurger.cs

示例8: SetIntervalCancel

        public void SetIntervalCancel()
        {
            // arrange
            var loop = new EventLoop();
            loop.Start(() => { });
            var callbackinvoked = new ManualResetEvent(false);
            var callback = new Action(() => callbackinvoked.Set());
            var timeout = TimeSpan.FromMilliseconds(100);

            // act
            var timer = loop.SetInterval(callback, timeout);
            timer.Cancel();

            // assert
            Assert.That(callbackinvoked.WaitOne(timeout + timeout), Is.False);

            // cleanup
            loop.Dispose();
            callbackinvoked.Dispose();
        }
开发者ID:oldslowfatstu,项目名称:NLoop,代码行数:20,代码来源:SetTimeoutExtensionsTests.cs

示例9: FromCommandLineArgsRaceCondition

        public void FromCommandLineArgsRaceCondition() {
            // https://pytools.codeplex.com/workitem/1429

            var mre = new ManualResetEvent(false);
            var tasks = new Task<bool>[100];
            try {
                for (int i = 0; i < tasks.Length; i += 1) {
                    tasks[i] = Task.Run(() => {
                        mre.WaitOne();
                        using (var arg = VisualStudioProxy.FromProcessId(123)) {
                            return arg is VisualStudioProxy;
                        }
                    });
                }
                mre.Set();
                Assert.IsTrue(Task.WaitAll(tasks, TimeSpan.FromSeconds(30.0)));
                Assert.IsTrue(tasks.All(t => t.Result));
            } finally {
                mre.Dispose();
                Task.WaitAll(tasks, TimeSpan.FromSeconds(30.0));
            }
        }
开发者ID:jsschultz,项目名称:PTVS,代码行数:22,代码来源:TestExecutorTests.cs

示例10: AcceptServerTransport

        internal static TransportBase AcceptServerTransport(TransportSettings settings)
        {
            ManualResetEvent complete = new ManualResetEvent(false);
            int closed = 0;
            TransportBase transport = null;

            Action<TransportListener, TransportAsyncCallbackArgs> onTransport = (l, a) =>
            {
                if (a.Exception != null)
                {
                    Debug.WriteLine(a.Exception.Message);
                }
                else
                {
                    Debug.WriteLine("Listener accepted a transport.");
                    transport = a.Transport;
                }

                if (Interlocked.Exchange(ref closed, 1) == 0)
                {
                    complete.Set();
                }
            };

            TransportListener listener = settings.CreateListener();
            Debug.WriteLine("Listeners are waiting for connections...");
            listener.Listen(onTransport);

            complete.WaitOne();
            complete.Dispose();

            transport.Closed += (s, a) =>
            {
                listener.Close();
                Debug.WriteLine("Listeners Closed.");
            };

            return transport;
        }
开发者ID:Azure,项目名称:azure-amqp,代码行数:39,代码来源:AmqpTransportTests.cs

示例11: WaitWhileLocked

 /// <summary>
 /// Подождать пока объект не освободится
 /// </summary>
 /// <param name="actionKey">Уникальный ключ операции</param>
 public static void WaitWhileLocked(string actionKey)
 {
     var waitWhileNotUnlocked = new ManualResetEvent(true);
     lock (_lockerLock)
     {
         if (_lockedObjects.Contains(actionKey))
         {
             if (!_waitingThreads.ContainsKey(actionKey))
             {
                 _waitingThreads.Add(actionKey, new List<ManualResetEvent>());
             }
             _waitingThreads[actionKey].Add(waitWhileNotUnlocked);
             waitWhileNotUnlocked.Reset();
         }
         else
         {
             waitWhileNotUnlocked.Set();
         }
     }
     waitWhileNotUnlocked.WaitOne();
     waitWhileNotUnlocked.Dispose();
 }
开发者ID:ogoun,项目名称:Domain.Framework,代码行数:26,代码来源:TopLevelEntityLocker.cs

示例12: Socket_ConnectAsyncDnsEndPoint_HostNotFound

        public void Socket_ConnectAsyncDnsEndPoint_HostNotFound()
        {
            Assert.True(Capability.IPv4Support());

            SocketAsyncEventArgs args = new SocketAsyncEventArgs();
            args.RemoteEndPoint = new DnsEndPoint("notahostname.invalid.corp.microsoft.com", UnusedPort);
            args.Completed += OnConnectAsyncCompleted;

            ManualResetEvent complete = new ManualResetEvent(false);
            args.UserToken = complete;

            Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            bool willRaiseEvent = sock.ConnectAsync(args);
            if (willRaiseEvent)
            {
                complete.WaitOne();
            }

            AssertHostNotFoundOrNoData(args);

            complete.Dispose();
            sock.Dispose();
        }
开发者ID:nbilling,项目名称:corefx,代码行数:24,代码来源:DnsEndPointTest.cs

示例13: AwaitUpdater

        /// <summary>
        /// 
        /// </summary>
        /// <param name="usercontrol"></param>
        /// <returns>false if the user skipped.</returns>
        public Task<bool> AwaitUpdater(UserControl usercontrol, IProductUpdate productUpdate)
        {
            var updateSkeletonControl = usercontrol as Updating.Userinterface.UpdateSkeletonControl;

            if(updateSkeletonControl == null)
                throw new InvalidCastException("Control is not an UpdateSkeletonControl");

            if(updateSkeletonControl.DataContext == null)
                throw new NullReferenceException("Datacontext of UpdateSkeletonControl not set");

            var updatePropopsalViewModel =  updateSkeletonControl.DataContext as UpdatePropopsalViewModel;

            if(updatePropopsalViewModel == null)
                throw new InvalidCastException("Datacontext of UpdateSkeletonControl is not of type UpdateProposalViewModel");

            var manualResetEvent = new ManualResetEvent(false);

            updatePropopsalViewModel.ViewModelInteraction.CloseWindow = () => manualResetEvent.Set();

            var awaiterTask = new Task<bool>(() =>
            {
                // Wait for the async task to complete.
                manualResetEvent.WaitOne();

                // Dispose the manual reset event.
                manualResetEvent.Dispose();

                // Determine if we should close.
                return productUpdate.IsManadatory;

            });

            awaiterTask.Start();

            return awaiterTask;
        }
开发者ID:jormenjanssen,项目名称:Soundboard,代码行数:41,代码来源:UserInterfaceFactory.cs

示例14: Socket_ConnectAsyncDnsEndPoint_Success

        public void Socket_ConnectAsyncDnsEndPoint_Success(SocketImplementationType type)
        {
            Assert.True(Capability.IPv4Support());

            int port;
            SocketTestServer server = SocketTestServer.SocketTestServerFactory(type, IPAddress.Loopback, out port);

            SocketAsyncEventArgs args = new SocketAsyncEventArgs();
            args.RemoteEndPoint = new DnsEndPoint("localhost", port);
            args.Completed += OnConnectAsyncCompleted;

            ManualResetEvent complete = new ManualResetEvent(false);
            args.UserToken = complete;

            Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            bool willRaiseEvent = sock.ConnectAsync(args);
            if (willRaiseEvent)
            {
                Assert.True(complete.WaitOne(TestSettings.PassingTestTimeout), "Timed out while waiting for connection");
            }

            Assert.Equal(SocketError.Success, args.SocketError);
            Assert.Null(args.ConnectByNameError);

            complete.Dispose();
            sock.Dispose();
            server.Dispose();
        }
开发者ID:shmao,项目名称:corefx,代码行数:29,代码来源:DnsEndPointTest.cs

示例15: Stop

        /// <summary>
        /// Allows to stop the adapter.
        /// 
        /// Before returning, and if it is so configured,
        /// the adapter sends a "suspend" request to 
        /// all the currently registred fixtures.
        /// </summary>
        public void Stop()
        {
            _logger.InfoFormat("Adapter is stopping");

            try
            {
                if (_trigger != null)
                {
                    var wait_handler = new ManualResetEvent(false);
                    _trigger.Dispose(wait_handler);
                    wait_handler.WaitOne();
                    wait_handler.Dispose();
                    _trigger = null;
                    _fixtureManager.Dispose();
                }

                if (PlatformConnector != null)
                    PlatformConnector.Dispose();

                UDAPIService.Disconnect();
            }
            catch (Exception e)
            {
                _logger.Error("An error occured while disposing the adapter", e);
            }
            
            _stats.SetValue(AdapterCoreKeys.ADAPTER_STARTED, "0");
            _logger.InfoFormat("Adapter stopped");
        }
开发者ID:luxbet,项目名称:SS.Integration.Adapter,代码行数:36,代码来源:Adapter.cs


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