本文整理汇总了C#中System.Threading.ManualResetEvent.WaitUntilSetOrDie方法的典型用法代码示例。如果您正苦于以下问题:C# ManualResetEvent.WaitUntilSetOrDie方法的具体用法?C# ManualResetEvent.WaitUntilSetOrDie怎么用?C# ManualResetEvent.WaitUntilSetOrDie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.ManualResetEvent
的用法示例。
在下文中一共展示了ManualResetEvent.WaitUntilSetOrDie方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ItWorks
public void ItWorks()
{
using (AppConfig.Change(AppConfigPath))
using (var adapter = new BuiltinContainerAdapter())
{
var messageHandled = new ManualResetEvent(false);
adapter.Handle<string>(s => messageHandled.Set());
var bus = Configure.With(adapter)
.Transport(t => t.UseMsmqAndGetInputQueueNameFromAppConfig())
.CreateBus()
.Start();
bus.SendLocal("hello there!");
messageHandled.WaitUntilSetOrDie(5.Seconds());
}
var auditedMessages = MsmqTestHelper
.GetMessagesFrom(AuditQueue)
.ToList();
Assert.That(auditedMessages.Count, Is.EqualTo(1), "Expected to find exactly one copy of the sent message in the audit queue");
Assert.That(auditedMessages.Single().Messages[0], Is.EqualTo("hello there!"));
}
示例2: RequestReply
public void RequestReply()
{
var replyHandled = new ManualResetEvent(false);
var bus = StartBus(1);
adapter.HandleAsync<SomeMessage>(async message =>
{
var delay = message.Delay;
await Task.Delay(delay);
bus.Reply("yo!");
});
adapter.Handle<string>(str =>
{
if (str == "yo!")
{
Console.WriteLine("Got reply!");
replyHandled.Set();
}
});
bus.SendLocal(new SomeMessage { Delay = 1.Seconds() });
Console.WriteLine("Waiting for reply...");
replyHandled.WaitUntilSetOrDie(2.Seconds());
Console.WriteLine("Bam!");
}
示例3: RunTest
public void RunTest(bool useLowLatencyBackoffStrategy, int iterations)
{
var adapter = new BuiltinContainerAdapter();
var messageHasBeenReceived = new ManualResetEvent(false);
adapter.Handle<string>(s => messageHasBeenReceived.Set());
ConfigureBus(adapter, useLowLatencyBackoffStrategy);
var bus = adapter.Bus;
var recordedLatencies = new List<TimeSpan>();
iterations.Times(() =>
{
// let things calm down
Console.Write("Calming down.... ");
Thread.Sleep(30.Seconds());
Console.Write("Sending! ");
var sendTime = DateTime.UtcNow;
bus.SendLocal("w0000tamafooook!!1");
Console.Write("waiting... ");
messageHasBeenReceived.WaitUntilSetOrDie(20.Seconds());
var elapsedUntilNow = sendTime.ElapsedUntilNow();
Console.WriteLine("got the message - recorded latency of {0}", elapsedUntilNow);
recordedLatencies.Add(elapsedUntilNow);
messageHasBeenReceived.Reset();
});
Console.WriteLine("AVERAGE RECORDED LATENCY: {0:0.00} s", recordedLatencies.Average(t => t.TotalSeconds));
}
示例4: SequenceOfEventsIsRightAndMessageContextIsAvailableAsItShouldBe
public void SequenceOfEventsIsRightAndMessageContextIsAvailableAsItShouldBe()
{
var done = new ManualResetEvent(false);
builtinContainerAdapter.HandleAsync<string>(async str =>
{
WriteEvent(string.Format("context before doing anything: {0}, tx: {1}, current thread: {2}", MessageContext.HasCurrent, TransactionContext.Current, Thread.CurrentThread.Name));
await Task.Delay(TimeSpan.FromSeconds(3));
WriteEvent(string.Format("context after first await: {0}, tx: {1}, current thread: {2}", MessageContext.HasCurrent, TransactionContext.Current, Thread.CurrentThread.Name));
await Task.Delay(TimeSpan.FromSeconds(3)).ConfigureAwait(false);
WriteEvent(string.Format("context after ConfigureAwait(false): {0}, tx: {1}, current thread: {2}", MessageContext.HasCurrent, TransactionContext.Current, Thread.CurrentThread.Name));
done.Set();
});
builtinContainerAdapter.Bus.SendLocal("hej med dig!");
done.WaitUntilSetOrDie(TimeSpan.FromSeconds(10));
Thread.Sleep(TimeSpan.FromSeconds(1));
var eventsArray = events.ToArray();
Console.WriteLine(@"
------------------------------------------------------------------
Got events:
{0}
------------------------------------------------------------------
", string.Join(Environment.NewLine, eventsArray));
Assert.That(eventsArray, Is.EqualTo(new[]
{
"msg context established",
"uow started",
"context before doing anything: True, tx: handler tx on thread 'Rebus 1 worker 1', current thread: Rebus 1 worker 1",
"context after first await: True, tx: handler tx on thread 'Rebus 1 worker 1', current thread: Rebus 1 worker 1",
"context after ConfigureAwait(false): True, tx: handler tx on thread 'Rebus 1 worker 1', current thread: ",
"uow commit",
"uow dispose",
"msg context disposed"
}));
}
示例5: CanDoIt
public void CanDoIt()
{
var resetEvent = new ManualResetEvent(false);
var stringMessageWasReceived = false;
var activator = new HandlerActivatorForTesting()
.Handle<string>(str =>
{
stringMessageWasReceived = true;
resetEvent.Set();
});
var bus = CreateBus(InputQueueName, activator).Start();
bus.Advanced.Routing.Send(InputQueueName + "@" + Environment.MachineName, "wolla my friend!");
resetEvent.WaitUntilSetOrDie(5.Seconds(), "Did not receive the message");
stringMessageWasReceived.ShouldBe(true);
}
示例6: ContinuesOnAnyWorkerThreadWithContext
public void ContinuesOnAnyWorkerThreadWithContext()
{
var done = new ManualResetEvent(false);
var result = "";
Thread initial = null;
Thread final = null;
adapter.HandleAsync<SomeMessage>(async message =>
{
initial = Thread.CurrentThread;
MessageContext.GetCurrent().Items["somecontext"] = "inital";
Console.WriteLine("Started on thread " + initial.ManagedThreadId);
do
{
await Task.Delay(message.Delay);
} while (Thread.CurrentThread.ManagedThreadId == initial.ManagedThreadId);
final = Thread.CurrentThread;
result = MessageContext.GetCurrent().Items["somecontext"] + "final";
Console.WriteLine("Ended on thread " + final.ManagedThreadId);
done.Set();
});
var bus = StartBus(10);
bus.SendLocal(new SomeMessage { Delay = TimeSpan.FromSeconds(1) });
// wait for a long time, just to be sure some other worker thread will pick it up
done.WaitUntilSetOrDie(TimeSpan.FromMinutes(1));
result.ShouldBe("initalfinal");
initial.ShouldNotBe(final);
initial.Name.ShouldContain("Rebus 1 worker");
final.Name.ShouldContain("Rebus 1 worker");
}
示例7: PeekLockRenewalJustWorks
public void PeekLockRenewalJustWorks()
{
var done = new ManualResetEvent(false);
adapter.HandleAsync(async (string str) =>
{
LogEvent("entered!");
await Task.Delay(TimeSpan.FromMinutes(1));
LogEvent("waited one minute");
await Task.Delay(TimeSpan.FromMinutes(1));
LogEvent("waited two minutes");
await Task.Delay(TimeSpan.FromMinutes(1));
LogEvent("waited three minutes");
LogEvent("done!");
done.Set();
});
Console.WriteLine("Starting!");
adapter.Bus.SendLocal("hej");
done.WaitUntilSetOrDie(TimeSpan.FromMinutes(5));
Console.WriteLine("Done!");
Console.WriteLine();
Console.WriteLine(@"LOG---------------------------------------------------------------------
{0}
------------------------------------------------------------------------", string.Join(Environment.NewLine, events));
}
示例8: WorksWithSomeNumberOfRetries
public void WorksWithSomeNumberOfRetries(int numberOfRetries)
{
// arrange
var messageMovedToErrorQueueEvent = new ManualResetEvent(false);
var adapter = TrackDisposable(new BuiltinContainerAdapter());
var deliveryCount = 0;
adapter.Handle<string>(str =>
{
deliveryCount++;
throw new FacilityException("wut?");
});
InitializeBus(numberOfRetries, adapter, messageMovedToErrorQueueEvent);
var stopwatch = Stopwatch.StartNew();
using (var infoTimer = new Timer(2000))
{
infoTimer.Elapsed += delegate
{
Console.WriteLine("{0} delivery attempts - {1:0.0}s elapsed",
deliveryCount, stopwatch.Elapsed.TotalSeconds);
};
infoTimer.Start();
// act
adapter.Bus.SendLocal("ACT!!11");
var timeout = (numberOfRetries*0.5).Seconds();
messageMovedToErrorQueueEvent.WaitUntilSetOrDie(timeout, "Only managed to track {0} deliveries", deliveryCount);
Thread.Sleep(1.Seconds());
}
// assert
Assert.That(deliveryCount, Is.EqualTo(numberOfRetries));
}
示例9: RestoresContext
public void RestoresContext()
{
var done = new ManualResetEvent(false);
var result = "";
adapter.HandleAsync<SomeMessage>(async message =>
{
MessageContext.GetCurrent().Items["somecontext"] = "asger";
await Task.Delay(message.Delay);
MessageContext.GetCurrent().Items["somecontext"] += " heller";
await Task.Delay(message.Delay);
MessageContext.GetCurrent().Items["somecontext"] += " hallas";
await Task.Delay(message.Delay);
result = MessageContext.GetCurrent().Items["somecontext"] + " waits no more!";
done.Set();
});
var bus = StartBus(1);
bus.SendLocal(new SomeMessage { Delay = TimeSpan.FromSeconds(1) });
done.WaitUntilSetOrDie(5.Seconds());
result.ShouldBe("asger heller hallas waits no more!");
}
示例10: ContinuesOnWorkerThread
public void ContinuesOnWorkerThread()
{
var done = new ManualResetEvent(false);
adapter.HandleAsync<SomeMessage>(async message =>
{
Console.WriteLine("Intro");
var thread = Thread.CurrentThread.ManagedThreadId;
await Task.Delay(message.Delay);
Console.WriteLine("First continuation");
Thread.CurrentThread.ManagedThreadId.ShouldBe(thread);
await Task.Delay(message.Delay);
Console.WriteLine("Second continuation");
Thread.CurrentThread.ManagedThreadId.ShouldBe(thread);
await Task.Delay(message.Delay);
Console.WriteLine("Third and final continuation");
Thread.CurrentThread.ManagedThreadId.ShouldBe(thread);
done.Set();
});
var bus = StartBus(1);
bus.SendLocal(new SomeMessage { Delay = TimeSpan.FromSeconds(1) });
done.WaitUntilSetOrDie(5.Seconds());
}
示例11: SyncTaskRunWorks
public void SyncTaskRunWorks()
{
var done = new ManualResetEvent(false);
adapter.Handle<SomeMessage>(message =>
{
Console.WriteLine("Handling");
Task.Run(() => { }).Wait();
done.Set();
});
var bus = StartBus(1);
bus.SendLocal(new SomeMessage());
done.WaitUntilSetOrDie(1.Seconds());
}
示例12: MessageIsOnlyHandledOnce
public void MessageIsOnlyHandledOnce()
{
var done = new ManualResetEvent(false);
var bus = StartBus(1);
var i = 0;
adapter.HandleAsync<SomeMessage>(async message =>
{
i++;
await Task.Delay(5.Seconds());
done.Set();
});
bus.SendLocal(new SomeMessage());
done.WaitUntilSetOrDie(50.Seconds());
i.ShouldBe(1);
}