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


C# ActionBlock.Post方法代码示例

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


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

示例1: ActionBlockSample

        private static void ActionBlockSample()
        {
            var processInput = new ActionBlock<string>(s =>
            {
                Console.WriteLine("user input: {0}", s);
            });

            processInput.Post("111");
            processInput.Post("222");
        }
开发者ID:xxy1991,项目名称:cozy,代码行数:10,代码来源:A9DataFlow.cs

示例2: TestPost

 public void TestPost()
 {
     foreach (bool bounded in DataflowTestHelpers.BooleanValues)
     {
         ActionBlock<int> ab = new ActionBlock<int>(i => { },
             new ExecutionDataflowBlockOptions { BoundedCapacity = bounded ? 1 : -1 }); // test greedy and then non-greedy
         Assert.True(ab.Post(0), "Expected non-completed ActionBlock to accept Post'd message");
         ab.Complete();
         Assert.False(ab.Post(0), "Expected Complete'd ActionBlock to decline messages");
     }
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:11,代码来源:ActionBlockTests.cs

示例3: WriteOneLatency_OneMetricFlushed_Success

    public void WriteOneLatency_OneMetricFlushed_Success()
    {
      _block = TimedLatencyAggregatorBlockFactory.CreateBlock(_outputBuffer,
        String.Empty,
        _intervalService,
        true,
        _log.Object);
      var pulseDate = DateTime.Now;

      _block.Post(new Timing("foo.bar.baz", 100));
      _block.WaitUntilAllItemsProcessed();
      _intervalService.Pulse(pulseDate);

      Assert.AreEqual(new GraphiteLine("foo.bar.baz.count", 1, pulseDate.ToEpoch()),_outputBuffer.GetGraphiteLine(0));
      Assert.AreEqual(new GraphiteLine("foo.bar.baz.min", 100, pulseDate.ToEpoch()), _outputBuffer.GetGraphiteLine(1));
      Assert.AreEqual(new GraphiteLine("foo.bar.baz.max", 100, pulseDate.ToEpoch()), _outputBuffer.GetGraphiteLine(2));
      Assert.AreEqual(new GraphiteLine("foo.bar.baz.mean", 100, pulseDate.ToEpoch()), _outputBuffer.GetGraphiteLine(3));
      Assert.AreEqual(new GraphiteLine("foo.bar.baz.sum", 100, pulseDate.ToEpoch()), _outputBuffer.GetGraphiteLine(4));
      Assert.AreEqual(new GraphiteLine("foo.bar.baz.sumSquares", 10000, pulseDate.ToEpoch()), _outputBuffer.GetGraphiteLine(5));
      Assert.AreEqual(6, _outputBuffer.GraphiteLines.Count);
      // Ensure that min, max, mean and sum are all equal
      Assert.IsTrue(_outputBuffer.GetGraphiteLine(1).Quantity == _outputBuffer.GetGraphiteLine(2).Quantity 
        && _outputBuffer.GetGraphiteLine(2).Quantity == _outputBuffer.GetGraphiteLine(3).Quantity
        && _outputBuffer.GetGraphiteLine(3).Quantity == _outputBuffer.GetGraphiteLine(4).Quantity);
    }
开发者ID:houcine,项目名称:statsd.net,代码行数:25,代码来源:TimedLatencyAggregatorBlockTests.cs

示例4: Run

        public void Run()
        {
            this.output.WriteLine("TPL start");
            this.CheckFileExists();

            var f = new FileInfo(this.sampleLogFileName);
            this.fileSizeInBytes = f.Length;
            this.lineSizeInBytesSoFar = 0;
            this.lineCount = 0;

            var sw = new Stopwatch();
            sw.Start();

            var options = new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = 8 };

            var ab = new ActionBlock<string>(s => this.ProcessLine(s), options);

            using (TextReader reader = File.OpenText(this.sampleLogFileName))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    ab.Post(line);
                }
            }

            ab.Complete();
            ab.Completion.Wait();

            sw.Stop();
            this.ShowResults();

            this.output.WriteLine();
            this.output.WriteLine("TPL done in {0}", sw.Elapsed);
        }
开发者ID:KeesDijk,项目名称:AsyncDemo,代码行数:35,代码来源:TPLDataFlowRunner.cs

示例5: Test

        static void Test()
        {
            ConcurrentExclusiveSchedulerPair pair = new ConcurrentExclusiveSchedulerPair();

            readerAB1 = new ActionBlock<int>((i) =>
            {
                Console.WriteLine(i + "  ReaderAB1 begin handing." + " Excute Time:" + DateTime.Now +
                                  " currentThreadId : " + Thread.CurrentThread.ManagedThreadId);
                Thread.Sleep(500);
            }, new ExecutionDataflowBlockOptions() {TaskScheduler = pair.ConcurrentScheduler});

            readerAB2 = new ActionBlock<int>((i) =>
            {
                Console.WriteLine(i + "  ReaderAB2 begin handing." + " Excute Time:" + DateTime.Now +
                                  " currentThreadId : " + Thread.CurrentThread.ManagedThreadId);
                Thread.Sleep(500);
            }, new ExecutionDataflowBlockOptions() {TaskScheduler = pair.ConcurrentScheduler});

            readerAB3 = new ActionBlock<int>((i) =>
            {
                Console.WriteLine(i + "  ReaderAB3 begin handing." + " Excute Time:" + DateTime.Now +
                                  " currentThreadId : " + Thread.CurrentThread.ManagedThreadId);
                Thread.Sleep(500);
            }, new ExecutionDataflowBlockOptions() {TaskScheduler = pair.ConcurrentScheduler});

            writeAB1 = new ActionBlock<int>((i) =>
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(i + "  writeAB1 begin handing." + " Excute Time:" + DateTime.Now +
                                  " currentThreadId : " + Thread.CurrentThread.ManagedThreadId);
                Console.ResetColor();
                Thread.Sleep(3000);
            }, new ExecutionDataflowBlockOptions() {TaskScheduler = pair.ExclusiveScheduler});

            bb.LinkTo(readerAB1);
            bb.LinkTo(readerAB2);
            bb.LinkTo(readerAB3);

            var task1 = Task.Run(() =>
            {
                while (true)
                {
                    bb.Post(1);
                    Thread.Sleep(1000);
                }
            });

            var task2 = Task.Run(() =>
            {
                while (true)
                {
                    writeAB1.Post(1);
                    Thread.Sleep(6000);
                }
            });

            Task.WaitAll(task1, task2);
        }
开发者ID:HawkingChan,项目名称:TaskAsyncProject,代码行数:58,代码来源:Program.cs

示例6: Start

        public void Start(string root)
        {
            _token = new CancellationTokenSource();
            _task = Loop((now, ct) => SendMessagesAsync(ct), _token.Token);
            _task.Post(DateTimeOffset.Now);
            _root = root;
            //_stopwatch.Start();

            Frontier.Push(_root, null);
        }
开发者ID:abarbarov,项目名称:crawler,代码行数:10,代码来源:MessageSender.cs

示例7: TestBlockBufferCount

        public async Task TestBlockBufferCount()
        {
            var block1 = new TransformBlock<int, int>(i => 2 * i);
            var block2 = new TransformManyBlock<int, int>(i => new [] { i });
            var block3 = new ActionBlock<int>(i => { Thread.Sleep(1000); });

            block1.Post(0);
            block2.Post(0);
            block2.Post(0);
            block3.Post(0);
            block3.Post(0);
            block3.Post(0);

            await Task.Delay(200);

            Assert.AreEqual(1, block1.GetBufferCount().Total());
            Assert.AreEqual(2, block2.GetBufferCount().Total());
            Assert.AreEqual(2, block3.GetBufferCount().Total());
        }
开发者ID:charles-schrupp,项目名称:DataflowEx,代码行数:19,代码来源:BlockExtensionTest.cs

示例8: WriteFourLatencies_PercentileLogged_Success

    public void WriteFourLatencies_PercentileLogged_Success()
    {
      _block = TimedLatencyPercentileAggregatorBlockFactory.CreateBlock(_outputBuffer,
        String.Empty,
        _intervalService,
        90,
        null,
        _log.Object);

      _block.Post(new Timing("foo", 100));
      _block.Post(new Timing("foo", 200));
      _block.Post(new Timing("foo", 300));
      _block.Post(new Timing("foo", 400));
      _block.WaitUntilAllItemsProcessed();
      _intervalService.Pulse();

      Assert.IsTrue(_outputBuffer.GraphiteLines.Any(p => p.Name == "foo.p90"));
      Assert.AreEqual(400, _outputBuffer["foo.p90"]);
    }
开发者ID:houcine,项目名称:statsd.net,代码行数:19,代码来源:TimedLatencyPercentileAggregatorBlockTests.cs

示例9: WriteTwoLatencies_CalulateMinMaxMeanSum_Success

    public void WriteTwoLatencies_CalulateMinMaxMeanSum_Success()
    {
      _block = TimedLatencyAggregatorBlockFactory.CreateBlock(_outputBuffer,
        String.Empty,
        _intervalService,
        true,
        _log.Object);
      var pulseDate = DateTime.Now;

      _block.Post(new Timing("foo", 5));
      _block.Post(new Timing("foo", 15));
      _block.WaitUntilAllItemsProcessed();
      _intervalService.Pulse(pulseDate);

      Assert.AreEqual(15, _outputBuffer["foo.max"]);
      Assert.AreEqual(5, _outputBuffer["foo.min"]);
      Assert.AreEqual(10, _outputBuffer["foo.mean"]);
      Assert.AreEqual(2, _outputBuffer["foo.count"]);
      Assert.AreEqual(20, _outputBuffer["foo.sum"]);
    }
开发者ID:joshclark,项目名称:statsd.net,代码行数:20,代码来源:TimedLatencyAggregatorBlockTests.cs

示例10: BasicUsageTest

		public void BasicUsageTest ()
		{
			bool[] array = new bool[3];
			var evt = new CountdownEvent (array.Length);
			var block = new ActionBlock<int> (i => { array[i] = true; evt.Signal (); });

			for (int i = 0; i < array.Length; ++i)
				Assert.IsTrue (block.Post (i), "Not accepted");

			Assert.IsTrue (evt.Wait (500));
			
			Assert.IsTrue (array.All (b => b), "Some false");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:13,代码来源:ActionBlockTest.cs

示例11: CompleteTest

		public void CompleteTest ()
		{
			var block = new ActionBlock<int> (i => Thread.Sleep (100));

			for (int i = 0; i < 10; i++)
				Assert.IsTrue (block.Post (i), "Not Accepted");

			block.Complete ();
			// Still element to be processed so Completion should be false
			Assert.IsFalse (block.Completion.IsCompleted);
			block.Completion.Wait ();
			Assert.IsTrue (block.Completion.IsCompleted);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:13,代码来源:ActionBlockTest.cs

示例12: WriteOneHunderedLatencies_p90PercentileLogged_Success

    public void WriteOneHunderedLatencies_p90PercentileLogged_Success()
    {
      _block = TimedLatencyPercentileAggregatorBlockFactory.CreateBlock(_outputBuffer,
        String.Empty,
        _intervalService,
        90,
        null,
        _log.Object);

      TestUtility.Range(100, false).ForEach(p => _block.Post(new Timing("foo", p)));
      _block.WaitUntilAllItemsProcessed();
      _intervalService.Pulse();

      Assert.AreEqual(90, _outputBuffer["foo.p90"]);
    }
开发者ID:houcine,项目名称:statsd.net,代码行数:15,代码来源:TimedLatencyPercentileAggregatorBlockTests.cs

示例13: AsyncNullTest

		public void AsyncNullTest()
		{
			var scheduler = new TestScheduler ();
			var block = new ActionBlock<int> (
				i => null,
				new ExecutionDataflowBlockOptions { TaskScheduler = scheduler });

			Assert.IsTrue (block.Post (1));

			scheduler.ExecuteAll ();

			Assert.IsFalse (block.Completion.Wait (100));

			block.Complete ();

			Assert.IsTrue (block.Completion.Wait (100));
		}
开发者ID:nlhepler,项目名称:mono,代码行数:17,代码来源:ActionBlockTest.cs

示例14: ActionBlockSample

    private static void ActionBlockSample()
    {
      var processInput = new ActionBlock<string>(s =>
      {
        Console.WriteLine("user input: {0}", s);
      });

      bool exit = false;
      while (!exit)
      {
        string input = Console.ReadLine();
        if (string.Compare(input, "exit", ignoreCase: true) == 0)
        {
          exit = true;
        }
        else
        {
          processInput.Post(input);
        }
      }
    }
开发者ID:CNinnovation,项目名称:ParallelProgrammingFeb2016,代码行数:21,代码来源:Program.cs

示例15: TestEncapsulate_LinkingAndUnlinking

        public void TestEncapsulate_LinkingAndUnlinking()
        {
            var buffer = new BufferBlock<int>();
            var action = new ActionBlock<int>(i => buffer.Post(i));
            action.Completion.ContinueWith(delegate { buffer.Complete(); }, TaskScheduler.Default);
            IPropagatorBlock<int, int> encapsulated = DataflowBlock.Encapsulate(action, buffer);

            var endTarget = new BufferBlock<int>();

            IDisposable unlink = encapsulated.LinkTo(endTarget);
            Assert.NotNull(unlink);

            IDisposable unlink2 = encapsulated.LinkTo(endTarget);
            Assert.NotNull(unlink);

            action.Post(1);
            Assert.Equal(expected: 1, actual: endTarget.Receive());

            unlink.Dispose();
            action.Post(2);
            Assert.Equal(expected: 2, actual: endTarget.Receive());

            unlink2.Dispose();
        }
开发者ID:gitter-badger,项目名称:corefx,代码行数:24,代码来源:DataflowBlockExtensionTests.cs


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