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


C# ManualResetEvent.WaitOrDie方法代码示例

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


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

示例1: ItWorks

        public async Task ItWorks()
        {
            var sub1GotEvent = new ManualResetEvent(false);
            var sub2GotEvent = new ManualResetEvent(false);

            var sub1 = GetBus(_subscriber1QueueName, async str =>
            {
                if (str == "weehoo!!")
                {
                    sub1GotEvent.Set();
                }
            });

            var sub2 = GetBus(_subscriber2QueueName, async str =>
            {
                if (str == "weehoo!!")
                {
                    sub2GotEvent.Set();
                }
            });

            await sub1.Bus.Subscribe<string>();
            await sub2.Bus.Subscribe<string>();

            await _publisher.Bus.Publish("weehoo!!");

            sub1GotEvent.WaitOrDie(TimeSpan.FromSeconds(2));
            sub2GotEvent.WaitOrDie(TimeSpan.FromSeconds(2));
        }
开发者ID:nls75,项目名称:Rebus,代码行数:29,代码来源:RabbitMqPubSubTest.cs

示例2: ItWorks

        public void ItWorks()
        {
            var gotTheMessage = new ManualResetEvent(false);
            _handlerActivator.Handle<HugeMessage>(async msg =>
            {
                gotTheMessage.Set();
            });

            var hugePayload = string.Concat(Enumerable.Range(0, 128)
                .Select(i => string.Concat(Enumerable.Repeat(i.ToString(), 128))));

            _bus.SendLocal(new HugeMessage {Payload = hugePayload});

            gotTheMessage.WaitOrDie(TimeSpan.FromSeconds(2));

            var hugePayloadLength = hugePayload.Length;

            var sentMessageBodyLength = _sentMessages.Single().Body.Length;
            var receivedMessageBodyLength = _receivedMessages.Single().Body.Length;

            Console.WriteLine(@"
Huge payload:       {0}
Sent message:       {1}
Received message:   {2}", hugePayloadLength, sentMessageBodyLength, receivedMessageBodyLength);

            Assert.That(sentMessageBodyLength, Is.LessThan(hugePayloadLength));
            Assert.That(receivedMessageBodyLength, Is.LessThan(hugePayloadLength));
        }
开发者ID:netojoaop,项目名称:Rebus,代码行数:28,代码来源:TestEncryptionAndCompressionTogether.cs

示例3: CheckEncryptedMessages

        public void CheckEncryptedMessages()
        {
            var transportMessages = new ConcurrentQueue<TransportMessage>();

            _transportTap.MessageReceived += transportMessages.Enqueue;
            _transportTap.MessageSent += transportMessages.Enqueue;

            var gotMessage = new ManualResetEvent(false);

            _activator.Handle<string>(async message =>
            {
                if (message != "hej") throw new ArgumentException("not the right message!!");

                gotMessage.Set();
            });

            _activator.Bus.SendLocal("hej").Wait();

            gotMessage.WaitOrDie(TimeSpan.FromSeconds(3));

            var messages = transportMessages.ToList();

            Assert.That(messages.Count, Is.EqualTo(2));

            var headers = messages.First().Headers;

            Assert.That(headers[EncryptionHeaders.ContentEncryption], Is.EqualTo("silly"));
        }
开发者ID:RichieYang,项目名称:Rebus,代码行数:28,代码来源:TestCustomEncryption.cs

示例4: UsesNativeDeferralMechanism

        public async Task UsesNativeDeferralMechanism()
        {
            var done = new ManualResetEvent(false);
            var receiveTime = DateTimeOffset.MinValue;
            var hadDeferredUntilHeader = false;

            _activator.Handle<TimedMessage>(async (bus, context, message) =>
            {
                receiveTime = DateTimeOffset.Now;

                hadDeferredUntilHeader = context.TransportMessage.Headers.ContainsKey(Headers.DeferredUntil);

                done.Set();
            });

            var sendTime = DateTimeOffset.Now;

            await _bus.Defer(TimeSpan.FromSeconds(5), new TimedMessage { Time = sendTime });

            done.WaitOrDie(TimeSpan.FromSeconds(8), "Did not receive 5s-deferred message within 8 seconds of waiting....");

            var delay = receiveTime - sendTime;

            Console.WriteLine("Message was delayed {0}", delay);

            Assert.That(delay, Is.GreaterThan(TimeSpan.FromSeconds(4)), "The message not delayed ~5 seconds as expected!");
            Assert.That(delay, Is.LessThan(TimeSpan.FromSeconds(8)), "The message not delayed ~5 seconds as expected!");

            Assert.That(hadDeferredUntilHeader, Is.False, "Received message still had the '{0}' header - we must remove that", Headers.DeferredUntil);
        }
开发者ID:nls75,项目名称:Rebus,代码行数:30,代码来源:NativeDeferTest.cs

示例5: NizzleName

        public async Task NizzleName()
        {
            var gotMessage = new ManualResetEvent(false);

            using (var activator = new BuiltinHandlerActivator())
            {
                activator.Handle<string>(async s =>
                {
                    Console.WriteLine("Got message: {0}", s);
                    gotMessage.Set();
                });

                Configure.With(activator)
                    .Transport(t => t.UseInMemoryTransport(new InMemNetwork(), "bimse"))
                    .Options(o =>
                    {
                        o.Register<IWorkerFactory>(c =>
                        {
                            var transport = c.Get<ITransport>();
                            var pipeline = c.Get<IPipeline>();
                            var pipelineInvoker = c.Get<IPipelineInvoker>();
                            var rebusLoggerFactory = c.Get<IRebusLoggerFactory>();
                            return new AsyncTaskWorkerFactory(transport, pipeline, pipelineInvoker, rebusLoggerFactory);
                        });
                    })
                    .Start();

                await activator.Bus.SendLocal("hej med dig min ven");

                gotMessage.WaitOrDie(TimeSpan.FromSeconds(3));
            }
        }
开发者ID:hdrachmann,项目名称:Rebus,代码行数:32,代码来源:TestAlternativeWorkerFactory.cs

示例6: DoesNotBarfInTheBackground

        public void DoesNotBarfInTheBackground()
        {
            var doneHandlingMessage = new ManualResetEvent(false);

            _activator.Handle<string>(async str =>
            {
                for (var count = 0; count < 5; count++)
                {
                    Console.WriteLine("waiting...");
                    await Task.Delay(TimeSpan.FromSeconds(20));
                }

                Console.WriteLine("done waiting!");

                doneHandlingMessage.Set();
            });

            _activator.Bus.SendLocal("hej med dig min ven!").Wait();

            doneHandlingMessage.WaitOrDie(TimeSpan.FromMinutes(2));

            var logLinesAboveInformation = _loggerFactory
                .Where(l => l.Level >= LogLevel.Warn)
                .ToList();

            Assert.That(!logLinesAboveInformation.Any(), "Expected no warnings - got this: {0}", string.Join(Environment.NewLine, logLinesAboveInformation));
        }
开发者ID:nls75,项目名称:Rebus,代码行数:27,代码来源:TestSqlServerTransportCleanup.cs

示例7: CanHandleMessagesInsideTranasctionScope

        public void CanHandleMessagesInsideTranasctionScope(bool useTransactionScope)
        {
            var done = new ManualResetEvent(false);
            var detectedAmbientTransaction = false;
            var activator = Using(new BuiltinHandlerActivator());

            activator.Handle<string>(async str =>
            {
                detectedAmbientTransaction = Transaction.Current != null;

                done.Set();
            });

            Configure.With(activator)
                .Transport(t => t.UseInMemoryTransport(new InMemNetwork(), "txtest"))
                .Options(o =>
                {
                    if (useTransactionScope)
                    {
                        o.HandleMessagesInsideTransactionScope();
                    }

                    o.LogPipeline();
                })
                .Start();

            activator.Bus.SendLocal("hej").Wait();

            done.WaitOrDie(TimeSpan.FromSeconds(2));

            Assert.That(detectedAmbientTransaction, Is.EqualTo(useTransactionScope), 
                "Detected: {0}, expected: {1}", detectedAmbientTransaction, useTransactionScope);
        }
开发者ID:nls75,项目名称:Rebus,代码行数:33,代码来源:TestTransactionScopeSupport.cs

示例8: CopiesProperlyHandledMessageToAuditQueue

        public async Task CopiesProperlyHandledMessageToAuditQueue()
        {
            var gotTheMessage = new ManualResetEvent(false);

            _adapter.Handle<string>(async _ =>
            {
                gotTheMessage.Set();
            });

            await _bus.SendLocal("woohooo!!!!");

            gotTheMessage.WaitOrDie(TimeSpan.FromSeconds(5));

            InMemTransportMessage message;
            var timer = Stopwatch.StartNew();

            while ((message = _network.GetNextOrNull("audit")) == null)
            {
                await Task.Delay(200);

                if (timer.Elapsed > TimeSpan.FromSeconds(2))
                {
                    Assert.Fail("Did not receive message copy within 2 seconds of waiting....");
                }
            }

            PrintHeaders(message);

            Assert.That(message.Headers.ContainsKey(AuditHeaders.AuditTime));
            Assert.That(message.Headers.ContainsKey(AuditHeaders.HandleTime));
            Assert.That(message.Headers.ContainsKey(Headers.Intent));
            Assert.That(message.Headers[Headers.Intent], Is.EqualTo(Headers.IntentOptions.PointToPoint));
        }
开发者ID:geffzhang,项目名称:Rebus,代码行数:33,代码来源:TestMessageAuditing.cs

示例9: CanSendAndReceive

        public async Task CanSendAndReceive()
        {
            var gotMessage = new ManualResetEvent(false);

            _handlerActivator
                .Handle<string>(async (bus, str) =>
                {
                    if (str == "hej med dig min ven!")
                    {
                        Console.WriteLine("w00t!");

                        await bus.Reply("t00t!");
                    }

                    if (str == "t00t!")
                    {
                        Console.WriteLine("got t++t!!!");

                        gotMessage.Set();
                    }
                });

            await _bus.Send("hej med dig min ven!");

            gotMessage.WaitOrDie(TimeSpan.FromSeconds(30));
        }
开发者ID:xenoputtss,项目名称:Rebus,代码行数:26,代码来源:TestRequestReply.cs

示例10: DoIt

        public async Task DoIt()
        {
            var builtinHandlerActivator = new BuiltinHandlerActivator();
            var allDone = false;
            var gotMessage = new ManualResetEvent(false);

            builtinHandlerActivator.Handle<string>(async _ =>
            {
                gotMessage.Set();

                await Task.Delay(2000);

                allDone = true;
            });

            var bus = Configure.With(builtinHandlerActivator)
                .Transport(t => t.UseInMemoryTransport(new InMemNetwork(), "shutdown with pending tasks"))
                .Start();

            using (bus)
            {
                await bus.SendLocal("hej");

                gotMessage.WaitOrDie(TimeSpan.FromSeconds(2));

                // make bus shut down here
            }

            Assert.That(allDone, Is.True, "The message was apparently not handled all the way to the end!!!");
        }
开发者ID:RichieYang,项目名称:Rebus,代码行数:30,代码来源:TestShutdownWithPendingTasks.cs

示例11: PubSubSeemsToWorkAlsoWithUnsubscribe

        public async Task PubSubSeemsToWorkAlsoWithUnsubscribe()
        {
            var gotString1 = new ManualResetEvent(false);
            var subscriber2GotTheMessage = false;

            _bus1.Handle<string>(async str => gotString1.Set());

            _bus2.Handle<string>(async str =>
            {
                subscriber2GotTheMessage = true;
            });

            await _bus1.Bus.Subscribe<string>();
            await _bus2.Bus.Subscribe<string>();

            await Task.Delay(500);

            await _bus2.Bus.Unsubscribe<string>();

            await Task.Delay(500);

            await _bus3.Bus.Publish("hello there!!!!");

            gotString1.WaitOrDie(TimeSpan.FromSeconds(2));

            Assert.That(subscriber2GotTheMessage, Is.False, "Didn't expect subscriber 2 to get the string since it was unsubscribed");
        }
开发者ID:RichieYang,项目名称:Rebus,代码行数:27,代码来源:TestAsbTopicsPubSub.cs

示例12: YeahItWorks

        public async Task YeahItWorks()
        {
            var events = new List<string>();
            var finishedHandled = new ManualResetEvent(false);

            _handlerActivator.Handle<string>(async str =>
            {
                await AppendEvent(events, "1");
                await AppendEvent(events, "2");
                await AppendEvent(events, "3");
                await AppendEvent(events, "4");
                finishedHandled.Set();
            });

            Console.WriteLine(string.Join(Environment.NewLine, events));

            await _bus.Send("hej med dig!");

            finishedHandled.WaitOrDie(TimeSpan.FromSeconds(10));

            Assert.That(events.Count, Is.EqualTo(4));
            Assert.That(events[0], Is.StringStarting("event=1"));
            Assert.That(events[1], Is.StringStarting("event=2"));
            Assert.That(events[2], Is.StringStarting("event=3"));
            Assert.That(events[3], Is.StringStarting("event=4"));
        }
开发者ID:RichieYang,项目名称:Rebus,代码行数:26,代码来源:TestAsyncHandler.cs

示例13: ItWorksWithComplexMessage

        public void ItWorksWithComplexMessage(bool withCompressionEnabled)
        {
            var activator = new BuiltinHandlerActivator();
            var gotIt = new ManualResetEvent(false);

            activator.Handle<TextMessage>(async str =>
            {
                if (string.Equals(str.Text, LongText))
                {
                    gotIt.Set();
                }
                else
                {
                    throw new Exception(string.Format("Received text with {0} chars did not match expected text with {1} chars!",
                        str.Text.Length, LongText.Length));
                }
            });

            Using(activator);

            var bus = CreateBus(withCompressionEnabled, activator);

            bus.SendLocal(new TextMessage {Text = LongText}).Wait();

            gotIt.WaitOrDie(TimeSpan.FromSeconds(10));
        }
开发者ID:nls75,项目名称:Rebus,代码行数:26,代码来源:TestCompressionIntegration.cs

示例14: DispatchesDynamicMessageWhenDotNetTypeCannotBeFound

        public void DispatchesDynamicMessageWhenDotNetTypeCannotBeFound()
        {
            var gotTheMessage = new ManualResetEvent(false);

            string messageText = null;

            _builtinHandlerActivator.Handle<dynamic>(async message =>
            {
                Console.WriteLine("Received dynamic message: {0}", message);

                messageText = message.something.text;

                gotTheMessage.Set();
            });

            var headers = new Dictionary<string, string>
            {
                {Headers.MessageId, Guid.NewGuid().ToString()},
                {Headers.ContentType, "application/json;charset=utf-8"},
            };

            var transportMessage = new TransportMessage(headers, Encoding.UTF8.GetBytes(@"{
    ""something"": {
        ""text"": ""OMG dynamic JSON BABY!!""
    }
}"));
            _network.Deliver(InputQueueName, new InMemTransportMessage(transportMessage));

            gotTheMessage.WaitOrDie(TimeSpan.FromSeconds(2));

            Assert.That(messageText, Is.EqualTo("OMG dynamic JSON BABY!!"));
        }
开发者ID:xenoputtss,项目名称:Rebus,代码行数:32,代码来源:TestDynamicJil.cs

示例15: CanSubscribeEvenThoughWeHaveNotConfiguredAnyEndpointMappings

        public async Task CanSubscribeEvenThoughWeHaveNotConfiguredAnyEndpointMappings()
        {
            var gotTheString = new ManualResetEvent(false);

            _activator.Handle<string>(async str => gotTheString.Set());

            await _activator.Bus.Subscribe<string>();

            await Task.Delay(500);

            await _activator.Bus.Publish("whooo hooo this is a string!!");

            gotTheString.WaitOrDie(TimeSpan.FromSeconds(2));
        }
开发者ID:xenoputtss,项目名称:Rebus,代码行数:14,代码来源:TestCentralizedInMemSubscriptionStorage.cs


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