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


C# BlockingQueue.TryDequeue方法代码示例

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


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

示例1: Dequeue_times_out_as_specified

 public void Dequeue_times_out_as_specified()
 {
     BlockingQueue<string> q = new BlockingQueue<string>();
     DateTime start = GlobalClock.UtcNow;
     string x;
     Assert.IsFalse(q.TryDequeue(TimeSpan.FromSeconds(1), out x));
     Assert.IsNull(x);
     TimeSpan elapsed = GlobalClock.UtcNow.Subtract(start);
     Assert.GreaterOrEqual(elapsed.TotalSeconds, 0.95);
     Assert.LessOrEqual(elapsed.TotalSeconds, 1.1d);
 }
开发者ID:nataren,项目名称:DReAM,代码行数:11,代码来源:BlockingQueueTests.cs

示例2: TestBlockingQueue

        public static void TestBlockingQueue()
        {
            var bq = new BlockingQueue<int>();
            var range = Arrays.Range(0, 1, 5);
            var list = new List<int>();
            for (int i = 0; i < 2 * range.Count; i++)
                ThreadPool.QueueUserWorkItem((o) =>
                {
                    int val;
                    if (!bq.TryDequeue(500, out val))
                        val = -1;

                    lock (list)
                        list.Add(val);
                });
            Thread.Sleep(10);
            foreach (var i in range)
                bq.Enqueue(i);

            var now = DateTime.Now;
            while ((DateTime.Now - now).TotalSeconds < 5)
            {
                lock (list)
                    if (list.Count >= 2 * range.Count)
                    {
                        if (list.Count > 2 * range.Count)
                            throw new Exception("Too many items");
                        if (list.Count(i => i == -1) != range.Count)
                            throw new Exception("Wrong number of -1's");
                        if (!list.Where(i => i != -1).InOrder().SequenceEqual(range))
                            throw new Exception("Wrong non-negative elements!");
                        return; // success
                    }

                Thread.Sleep(10);
            }

            throw new Exception("Failed to complete after 5 seconds!");
        }
开发者ID:madelson,项目名称:Emotiv-Experimenter,代码行数:39,代码来源:SyncTests.cs

示例3: RunTestsInSandbox

        /// <summary>
        /// Pulls tests from a queue and runs them inside a sandbox.
        /// </summary>
        /// <param name="queue"> The queue to retrieve tests from. </param>
        private void RunTestsInSandbox(BlockingQueue<TestExecutionState> queue)
        {
            // Set the DeserializationEnvironment so any JavaScriptExceptions can be serialized
            // accross the AppDomain boundary.
            ScriptEngine.DeserializationEnvironment = new ScriptEngine();

            int testCounter = 0;
            AppDomain appDomain = null;

            // Loop as long as there are tests in the queue.
            while (true)
            {
                if (testCounter == 0)
                {
                    // Unload the old AppDomain.
                    if (appDomain != null)
                        AppDomain.Unload(appDomain);

                    // Create an AppDomain with internet sandbox permissions.
                    var e = new System.Security.Policy.Evidence();
                    e.AddHostEvidence(new System.Security.Policy.Zone(System.Security.SecurityZone.Internet));
                    appDomain = AppDomain.CreateDomain(
                        "Jurassic sandbox",
                        null,
                        new AppDomainSetup() { ApplicationBase = AppDomain.CurrentDomain.BaseDirectory },
                        System.Security.SecurityManager.GetStandardSandbox(e));
                }

                // Retrieve a test from the queue.
                TestExecutionState executionState;
                if (queue.TryDequeue(out executionState) == false)
                    break;

                // Restore the ScriptEngine state.
                var scriptEngine = new ScriptEngine();
                foreach (var propertyNameAndValue in includeProperties)
                    scriptEngine.Global[propertyNameAndValue.Key] = propertyNameAndValue.Value;

                // Set strict mode.
                scriptEngine.ForceStrictMode = executionState.RunInStrictMode;

                // Create a new ScriptEngine instance inside the AppDomain.
                var engineHandle = Activator.CreateInstanceFrom(
                    appDomain,                                          // The AppDomain to create the type within.
                    typeof(ScriptEngineWrapper).Assembly.CodeBase,      // The file name of the assembly containing the type.
                    typeof(ScriptEngineWrapper).FullName,               // The name of the type to create.
                    false,                                              // Ignore case: no.
                    (System.Reflection.BindingFlags)0,                  // Binding flags.
                    null,                                               // Binder.
                    new object[] { scriptEngine },                      // Parameters passed to the constructor.
                    null,                                               // Culture.
                    null);                                              // Activation attributes.
                var scriptEngineProxy = (ScriptEngineWrapper)engineHandle.Unwrap();
                if (System.Runtime.Remoting.RemotingServices.IsTransparentProxy(scriptEngineProxy) == false)
                    throw new InvalidOperationException("Script engine not operating within the sandbox.");

                // Run the test.
                RunTest(scriptEngineProxy.Execute, executionState);

                // Reset the test count every 200 tests so the AppDomain gets recreated.
                // This saves us from an unavoidable memory leak in low privilege mode.
                testCounter++;
                if (testCounter == 200)
                    testCounter = 0;

            }
        }
开发者ID:ffarzat,项目名称:Jurassic,代码行数:71,代码来源:TestSuite.cs

示例4: RunTests

        /// <summary>
        /// Pulls tests from a queue and runs them.
        /// </summary>
        /// <param name="queue"> The queue to retrieve tests from. </param>
        private void RunTests(BlockingQueue<TestExecutionState> queue)
        {
            // Loop as long as there are tests in the queue.
            while (true)
            {
                // Retrieve a test from the queue.
                TestExecutionState executionState;
                if (queue.TryDequeue(out executionState) == false)
                    break;

                // Restore the ScriptEngine state.
                var scriptEngine = new ScriptEngine();
                foreach (var propertyNameAndValue in includeProperties)
                    scriptEngine.Global[propertyNameAndValue.Key] = propertyNameAndValue.Value;

                // Set strict mode.
                scriptEngine.ForceStrictMode = executionState.RunInStrictMode;

                // Run the test.
                RunTest(script =>
                {
                    try
                    {
                        scriptEngine.Execute(script);
                        return null;
                    }
                    catch (Exception ex)
                    {
                        return ex;
                    }
                }, executionState);

            }
        }
开发者ID:ffarzat,项目名称:Jurassic,代码行数:38,代码来源:TestSuite.cs


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