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


C# ConcurrentQueue.First方法代码示例

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


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

示例1: Given_Message_When_Sending_Then_Reply_Should_Be_Observed

        public async Task Given_Message_When_Sending_Then_Reply_Should_Be_Observed()
        {
            await With.RabbitMQHostedBusInstances(async (platibus0, platibus1) =>
            {
                var replyReceivedEvent = new ManualResetEvent(false);
                var repliesCompletedEvent = new ManualResetEvent(false);
                var replies = new ConcurrentQueue<object>();
                var message = new TestMessage
                {
                    GuidData = Guid.NewGuid(),
                    IntData = RNG.Next(0, int.MaxValue),
                    StringData = "Hello, world!",
                    DateData = DateTime.UtcNow
                };

                var sentMessage = await platibus0.Send(message);
                var subscription = sentMessage
                    .ObserveReplies()
                    .Subscribe(r =>
                    {
                        replies.Enqueue(r);
                        replyReceivedEvent.Set();
                    }, () => repliesCompletedEvent.Set());

                var replyReceived = await replyReceivedEvent.WaitOneAsync(TimeSpan.FromSeconds(30));
                var repliesCompleted = await repliesCompletedEvent.WaitOneAsync(TimeSpan.FromSeconds(30));
                subscription.Dispose();

                Assert.That(replyReceived, Is.True);
                Assert.That(repliesCompleted, Is.True);
                Assert.That(replies.Count, Is.EqualTo(1));

                var reply = replies.First();
                Assert.That(reply, Is.InstanceOf<TestReply>());
            });
        }
开发者ID:tdbrian,项目名称:Platibus,代码行数:36,代码来源:RabbitMQSendAndReplyTests.cs

示例2: Process

    public override IEnumerable<string> Process(string aPath)
    {
      PrepareBeforeProcessing(aPath);

      var result = new ConcurrentBag<string>();

      if (ParallelMode && sourceFiles.Count > 1)
      {
        var exceptions = new ConcurrentQueue<Exception>();

        int totalCount = sourceFiles.Count;

        Progress.SetRange(0, totalCount);

        var curFiles = new ConcurrentList<string>();
        var finishedFiles = new ConcurrentList<string>();
        var curProcessors = new ConcurrentList<IParallelTaskFileProcessor>();

        Parallel.ForEach(sourceFiles, Option, (sourceFile, loopState) =>
        {
          curFiles.Add(sourceFile);

          Progress.SetMessage("Processing {0}, finished {1} / {2}", curFiles.Count, finishedFiles.Count, totalCount);

          IParallelTaskFileProcessor processor = GetTaskProcessor(aPath, sourceFile);

          if (processor == null)
          {
            curFiles.Remove(sourceFile);
            finishedFiles.Add(sourceFile);
            return;
          }

          processor.LoopState = loopState;
          processor.Progress = Progress;

          curProcessors.Add(processor);
          try
          {
            var curResult = processor.Process(sourceFile);

            foreach (var f in curResult)
            {
              result.Add(f);
            }

            curFiles.Remove(sourceFile);
            finishedFiles.Add(sourceFile);

            Progress.SetPosition(finishedFiles.Count);
            Progress.SetMessage("Processing {0}, finished {1} / {2}", curFiles.Count, finishedFiles.Count, totalCount);
          }
          catch (Exception e)
          {
            exceptions.Enqueue(e);
            loopState.Stop();
          }

          GC.Collect();
        });

        if (Progress.IsCancellationPending())
        {
          throw new UserTerminatedException();
        }

        if (exceptions.Count > 0)
        {
          if (exceptions.Count == 1)
          {
            throw exceptions.First();
          }
          else
          {
            StringBuilder sb = new StringBuilder();
            foreach (var ex in exceptions)
            {
              sb.AppendLine(ex.ToString());
            }
            throw new Exception(sb.ToString());
          }
        }
      }
      else
      {
        for (int i = 0; i < sourceFiles.Count; i++)
        {
          if (Progress.IsCancellationPending())
          {
            throw new UserTerminatedException();
          }

          string rootMsg = MyConvert.Format("{0} / {1} : {2}", i + 1, sourceFiles.Count, sourceFiles[i]);

          Progress.SetMessage(1, rootMsg);

          IParallelTaskFileProcessor processor = GetTaskProcessor(aPath, sourceFiles[i]);
          processor.PrefixMessage = string.Format("{0} / {1} :", i + 1, sourceFiles.Count);
          processor.Progress = Progress;

//.........这里部分代码省略.........
开发者ID:shengqh,项目名称:RCPA.Core,代码行数:101,代码来源:AbstractParallelMainFileProcessor.cs


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