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


C# ManualResetEventSlim.Dispose方法代码示例

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


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

示例1: Evaluator

        public Evaluator(string jsShellPath, string options)
        {
            var psi = new ProcessStartInfo(
                jsShellPath, options
            ) {
                RedirectStandardInput = true,
                RedirectStandardOutput = true,
                RedirectStandardError = true,
                CreateNoWindow = true,
                UseShellExecute = false,
                WindowStyle = ProcessWindowStyle.Hidden
            };

            ManualResetEventSlim stdoutSignal, stderrSignal;
            stdoutSignal = new ManualResetEventSlim(false);
            stderrSignal = new ManualResetEventSlim(false);

            Process = Process.Start(psi);

            ThreadPool.QueueUserWorkItem((_) => {
                _StdOut = Process.StandardOutput.ReadToEnd();
                stdoutSignal.Set();
            });
            ThreadPool.QueueUserWorkItem((_) => {
                _StdErr = Process.StandardError.ReadToEnd();
                stderrSignal.Set();
            });

            _JoinImpl = () => {
                stdoutSignal.Wait();
                stderrSignal.Wait();
                stderrSignal.Dispose();
                stderrSignal.Dispose();
            };
        }
开发者ID:robterrell,项目名称:JSIL,代码行数:35,代码来源:EvaluatorPool.cs

示例2: Evaluator

        public Evaluator(string jsShellPath, string options, Dictionary<string, string> environmentVariables = null)
        {
            Id = Interlocked.Increment(ref NextId);

            var psi = new ProcessStartInfo(
                jsShellPath, options
            ) {
                RedirectStandardInput = true,
                RedirectStandardOutput = true,
                RedirectStandardError = true,
                CreateNoWindow = true,
                UseShellExecute = false,
                WindowStyle = ProcessWindowStyle.Hidden
            };

            if (environmentVariables != null) {
                foreach (var kvp in environmentVariables)
                    psi.EnvironmentVariables[kvp.Key] = kvp.Value;
            }

            ManualResetEventSlim stdoutSignal, stderrSignal;
            stdoutSignal = new ManualResetEventSlim(false);
            stderrSignal = new ManualResetEventSlim(false);

            Process = Process.Start(psi);

            ThreadPool.QueueUserWorkItem((_) => {
                try {
                    _StdOut = Process.StandardOutput.ReadToEnd();
                } catch {
                }
                stdoutSignal.Set();
            });
            ThreadPool.QueueUserWorkItem((_) => {
                try {
                    _StdErr = Process.StandardError.ReadToEnd();
                } catch {
                }
                stderrSignal.Set();
            });

            _JoinImpl = () => {
                stdoutSignal.Wait();
                stderrSignal.Wait();
                stderrSignal.Dispose();
                stderrSignal.Dispose();
            };
        }
开发者ID:jean80it,项目名称:JSIL,代码行数:48,代码来源:EvaluatorPool.cs

示例3: SuccessiveTimeoutTest

        public void SuccessiveTimeoutTest(HostType hostType, TransportType transportType, MessageBusType messageBusType)
        {
            using (var host = CreateHost(hostType, transportType))
            {
                // Arrange
                var mre = new ManualResetEventSlim(false);
                host.Initialize(keepAlive: 5, messageBusType: messageBusType);
                var connection = CreateConnection(host, "/my-reconnect");

                using (connection)
                {
                    connection.Reconnected += () =>
                    {
                        mre.Set();
                    };

                    connection.Start(host.Transport).Wait();

                    ((Client.IConnection)connection).KeepAliveData = new KeepAliveData(TimeSpan.FromMilliseconds(500));

                    // Assert that Reconnected is called
                    Assert.True(mre.Wait(TimeSpan.FromSeconds(15)));

                    // Assert that Reconnected is called again
                    mre.Reset();
                    Assert.True(mre.Wait(TimeSpan.FromSeconds(15)));

                    // Clean-up
                    mre.Dispose();
                }
            }
        }
开发者ID:RyanChristensen,项目名称:SignalR,代码行数:32,代码来源:KeepAliveFacts.cs

示例4: Main

        public static void Main(string[] args)
        {
            string url = "http://www.intelliTechture.com";
            if(args.Length > 0)
            {
                url = args[0];
            }

            Console.Write(url);
            WebRequest webRequest = WebRequest.Create(url);
            ManualResetEventSlim resetEvent =
                new ManualResetEventSlim();
            IAsyncResult asyncResult = webRequest.BeginGetResponse(
                (completedAsyncResult) =>
                {
                    HttpWebResponse response =
                        (HttpWebResponse)webRequest.EndGetResponse(
                            completedAsyncResult);
                    Stream stream = response.GetResponseStream();
                    StreamReader reader = new StreamReader(stream);
                    int length = reader.ReadToEnd().Length;

                    Console.WriteLine(FormatBytes(length));
                    resetEvent.Set();
                    resetEvent.Dispose();
                },
                null);

            // Indicate busy using dots
            while(!asyncResult.AsyncWaitHandle.WaitOne(100))
            {
                Console.Write('.');
            }
            resetEvent.Wait();
        }
开发者ID:rubycoder,项目名称:EssentialCSharp,代码行数:35,代码来源:AppendixC.03.PassingStateUsigClosureOnAnonymousMethod.cs

示例5: ReconnectionSuccesfulTest

        public void ReconnectionSuccesfulTest(HostType hostType, TransportType transportType, MessageBusType messageBusType)
        {
            using (var host = CreateHost(hostType, transportType))
            {
                // Arrange
                var mre = new ManualResetEventSlim(false);
                host.Initialize(keepAlive: null, messageBusType: messageBusType);
                var connection = CreateConnection(host, "/my-reconnect");

                using (connection)
                {
                    ((Client.IConnection)connection).KeepAliveData = new KeepAliveData(TimeSpan.FromSeconds(2));

                    connection.Reconnected += () =>
                    {
                        mre.Set();
                    };

                    connection.Start(host.Transport).Wait();

                    // Assert
                    Assert.True(mre.Wait(TimeSpan.FromSeconds(10)));

                    // Clean-up
                    mre.Dispose();
                }
            }
        }
开发者ID:RyanChristensen,项目名称:SignalR,代码行数:28,代码来源:KeepAliveFacts.cs

示例6: Dispose

        public void Dispose()
        {
            var mre = new ManualResetEventSlim(false);
            mre.Dispose();
            Assert.IsFalse(mre.IsSet, "#0a");

            try
            {
                mre.Reset();
                Assert.Fail("#1");
            }
            catch (ObjectDisposedException)
            {
            }

            mre.Set();

            try
            {
                mre.Wait(0);
                Assert.Fail("#3");
            }
            catch (ObjectDisposedException)
            {
            }

            try
            {
                var v = mre.WaitHandle;
                Assert.Fail("#4");
            }
            catch (ObjectDisposedException)
            {
            }
        }
开发者ID:mesheets,项目名称:Theraot-CF,代码行数:35,代码来源:ManualResetEventSlimTests.cs

示例7: Start

        /// <summary>
        /// Starts the IISExpress process that hosts the test site.
        /// </summary>
        public void Start()
        {
            _manualResetEvent = new ManualResetEventSlim(false);

            var thread = new Thread(StartIisExpress) { IsBackground = true };
            thread.Start();

            if (!_manualResetEvent.Wait(15000))
                throw new Exception("Could not start IIS Express");

            _manualResetEvent.Dispose();
        }
开发者ID:modulexcite,项目名称:dryrunner,代码行数:15,代码来源:TestSiteServer.cs

示例8: ManualResetEventSlim_SetAfterDisposeTest

        public void ManualResetEventSlim_SetAfterDisposeTest()
        {
            ManualResetEventSlim mre = new ManualResetEventSlim();

            ParallelTestHelper.Repeat(delegate
            {
                Exception disp = null, setting = null;

                CountdownEvent evt = new CountdownEvent(2);
                CountdownEvent evtFinish = new CountdownEvent(2);

                Task.Factory.StartNew(delegate
                {
                    try
                    {
                        evt.Signal();
                        evt.Wait(1000);
                        mre.Dispose();
                    }
                    catch (Exception e)
                    {
                        disp = e;
                    }
                    evtFinish.Signal();
                });
                Task.Factory.StartNew(delegate
                {
                    try
                    {
                        evt.Signal();
                        evt.Wait(1000);
                        mre.Set();
                    }
                    catch (Exception e)
                    {
                        setting = e;
                    }
                    evtFinish.Signal();
                });

                bool bb = evtFinish.Wait(1000);
                if (!bb)
                    Assert.AreEqual(true, evtFinish.IsSet);

                Assert.IsTrue(bb, "#0");
                Assert.IsNull(disp, "#1");
                Assert.IsNull(setting, "#2");

                evt.Dispose();
                evtFinish.Dispose();
            });
        }
开发者ID:mesheets,项目名称:Theraot-CF,代码行数:52,代码来源:WorkTest.cs

示例9: CancelBeforeWait

        public static void CancelBeforeWait()
        {
            ManualResetEventSlim mres = new ManualResetEventSlim();
            CancellationTokenSource cs = new CancellationTokenSource();
            cs.Cancel();
            CancellationToken ct = cs.Token;

            const int millisec = 100;
            TimeSpan timeSpan = new TimeSpan(100);

            EnsureOperationCanceledExceptionThrown(
               () => mres.Wait(ct), ct, "CancelBeforeWait:  An OCE should have been thrown.");
            EnsureOperationCanceledExceptionThrown(
               () => mres.Wait(millisec, ct), ct, "CancelBeforeWait:  An OCE should have been thrown.");
            EnsureOperationCanceledExceptionThrown(
               () => mres.Wait(timeSpan, ct), ct, "CancelBeforeWait:  An OCE should have been thrown.");
            mres.Dispose();
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:18,代码来源:ManualResetEventSlimCancellationTests.cs

示例10: Start

    public bool Start() {
      RegisterEvents();

      lastGenerationUpdate = String.Empty;
      lastTimespan = TimeSpan.Zero;
      finishedEventHandle = new ManualResetEventSlim(false, 1);
      Optimizer.Start();
      finishedEventHandle.Wait();

      if (Optimizer.ExecutionState == Core.ExecutionState.Started || Optimizer.ExecutionState == Core.ExecutionState.Paused) {
        Optimizer.Stop();
      }

      ContentManager.Save(new RunCollection(GetRun().ToEnumerable()), runInfo.SavePath, false);

      DeregisterEvents();
      finishedEventHandle.Dispose();
      return finishedSuccessfully;
    }
开发者ID:t-h-e,项目名称:HeuristicLab.ConsoleApplication,代码行数:19,代码来源:HLTask.cs

示例11: DistributedLock

        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="timeout">Seconds we will try to get the lock for.</param>
        /// <param name="ttl">Seconds until lock times out. Governs how frequently we extend the lock as well. Minimum of 10 seconds.</param>
        public DistributedLock(string name, int timeout = 10, int ttl = 30)
        {

            if (string.IsNullOrEmpty(name))
                throw new Exception("Distributed Lock Requires a Name");

            _ttl = ttl;
            if (_ttl < 10) throw new Exception("Minimum TTL is 10 seconds");

            _timeout = DateTime.UtcNow.AddSeconds(timeout);
            _client = new EtcdClient(Configuration.Instance.Hostnames[0]);
            _name = name;
            _handle = new ManualResetEventSlim(false);

            // get the unique ID of this locking instance
            _guid = Guid.NewGuid();

            // 1. try to create the node
            //    -> if already exists set up a watch to lock after it
            //       is given back.
            //       watch should also have the ID of the modifyIndex so 
            //       it will catch up if something happens in between

            // 2. extend the lock while it's active automatically
            //    by updating the TTL
            //    

            // this will attempt to get the lock and re-call itself
            // if there are multiple threads/servers attempting to 
            // get the same lock
            GetLock();

            // use the reset event to block this thread
            _handle.Wait(timeout * 1000);
            _handle.Dispose();

            if (_index == 0)
            {
                // we didn't get the lock
                throw new DistributedLockException("Could not aquire lock after retries");
            }
        }
开发者ID:james-andrewsmith,项目名称:Etcd.Modules,代码行数:48,代码来源:DistributedLock.cs

示例12: CancelBeforeWait

        public static bool CancelBeforeWait()
        {
            TestHarness.TestLog("* ManualResetEventCancellationTests.CancelBeforeWait()");
            bool passed = true;

            ManualResetEventSlim mres = new ManualResetEventSlim();
            CancellationTokenSource cs = new CancellationTokenSource();
            cs.Cancel();
            CancellationToken ct = cs.Token;
            
            const int millisec = 100;
            TimeSpan timeSpan = new TimeSpan(100);

            passed &= TestHarnessAssert.EnsureOperationCanceledExceptionThrown(() => mres.Wait(ct), ct, "An OCE should have been thrown.");
            passed &= TestHarnessAssert.EnsureOperationCanceledExceptionThrown(() => mres.Wait(millisec, ct), ct, "An OCE should have been thrown.");
            passed &= TestHarnessAssert.EnsureOperationCanceledExceptionThrown(() => mres.Wait(timeSpan, ct), ct, "An OCE should have been thrown.");
            mres.Dispose();

            return passed;
        }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:20,代码来源:ManualResetEventSlimCancellationTests.cs

示例13: RunManualResetEventSlimTest5_Dispose

        private static bool RunManualResetEventSlimTest5_Dispose()
        {
            bool passed = true;
            TestHarness.TestLog("* RunManualResetEventSlimTest5_Dispose()");
            ManualResetEventSlim mres = new ManualResetEventSlim(false);
            mres.Dispose();

            passed &= TestHarnessAssert.EnsureExceptionThrown(
               () => mres.Reset(),
               typeof(ObjectDisposedException),
               "The object has been disposed, should throw ObjectDisposedException.");

            passed &= TestHarnessAssert.EnsureExceptionThrown(
              () => mres.Wait(0),
              typeof(ObjectDisposedException),
              "The object has been disposed, should throw ObjectDisposedException.");


            passed &= TestHarnessAssert.EnsureExceptionThrown(
              () => 
              {
                  WaitHandle handle = mres.WaitHandle;
              },
              typeof(ObjectDisposedException),
              "The object has been disposed, should throw ObjectDisposedException.");

            mres = new ManualResetEventSlim(false); ;
            ManualResetEvent mre = (ManualResetEvent)mres.WaitHandle;
            mres.Dispose();

            passed &= TestHarnessAssert.EnsureExceptionThrown(
             () => mre.WaitOne(0, false),
             typeof(ObjectDisposedException),
             "The underlying event object has been disposed, should throw ObjectDisposedException.");

            return passed;
        }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:37,代码来源:CdsTests.cs

示例14: RunManualResetEventSlimTest2_TimeoutWait

        // Tests timeout on an event that is never set.
        private static bool RunManualResetEventSlimTest2_TimeoutWait()
        {
            TestHarness.TestLog("* RunManualResetEventSlimTest2_TimeoutWait()");

            ManualResetEventSlim ev = new ManualResetEventSlim(false);

            if (ev.Wait(0))
            {
                TestHarness.TestLog("  > ev.Wait(0) returned true -- event isn't set  ({0})", ev.IsSet);
                return false;
            }

            if (ev.Wait(100))
            {
                TestHarness.TestLog("  > ev.Wait(100) returned true -- event isn't set  ({0})", ev.IsSet);
                return false;
            }

            if (ev.Wait(TimeSpan.FromMilliseconds(100)))
            {
                TestHarness.TestLog("  > ev.Wait(0) returned true -- event isn't set  ({0})", ev.IsSet);
                return false;
            }

            ev.Dispose();

            return true;
        }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:29,代码来源:CdsTests.cs

示例15: Dispatch

        void Dispatch()
        {
            wh = new ManualResetEventSlim();

            while (true)
            {
                Task outTask = null;

                if (queue.TryDequeue(out outTask))
                {
                    Debug.WriteLine("--- Executing Task ---");
                    TryExecuteTask(outTask);
                    Debug.WriteLine("--- Done Executing Task ---");

                    if (stopped)
                    {
                        stopped = false;
                        dispatch = null;
                        queue = new ConcurrentQueue<Task>();

                        Debug.WriteLine("Scheduler stopped.");
                        del.OnStop(this);

                        break;
                    }
                }
                else
                {
                    wh.Wait();
                    wh.Reset();
                }
            }

            stopped = false;
            dispatch = null;
            wh.Dispose();
            wh = null;
        }
开发者ID:nathanklick,项目名称:SnowWhite.NET,代码行数:38,代码来源:KayakScheduler.cs


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