本文整理汇总了C#中Dispatcher.Subscribe方法的典型用法代码示例。如果您正苦于以下问题:C# Dispatcher.Subscribe方法的具体用法?C# Dispatcher.Subscribe怎么用?C# Dispatcher.Subscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dispatcher
的用法示例。
在下文中一共展示了Dispatcher.Subscribe方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
var d = new Dispatcher();
var midgetHouse = new MidgetHouse(d);
d.Subscribe<OrderPlaced>(midgetHouse);
d.Subscribe<DodgyOrderPlaced>(midgetHouse);
var manager = new Manager();
var cashier = new Cashier(d);
var ass = new AssMan(d);
var cookDispatcher = new SmartDispatcher<CookFood>();
var cookTtlGate = new TimeToLiveGate<CookFood>(cookDispatcher);
var cookQueudHandler = new QueuedHandler<CookFood>(cookTtlGate, "cook ttl gate");
var cookLimiter = new Limiter<CookFood>(cookQueudHandler);
//var cookScrewsUp = new ScrewsUp<CookFood>(cookLimiter);
var alarmClock = new AlarmClock(d);
var messageMonitor = new MessageMonitor(d);
var fmm = new FilePerOrderMonitor(d);
d.Subscribe(alarmClock);
d.Subscribe(cookLimiter);
d.Subscribe(ass);
d.Subscribe(cashier);
d.Subscribe(manager);
d.Subscribe<OrderPlaced>(messageMonitor);
d.Subscribe<DodgyOrderPlaced>(messageMonitor);
d.Subscribe<OrderPlaced>(fmm);
d.Subscribe<DodgyOrderPlaced>(fmm);
var cookQueudHandler1 = new QueuedHandler<CookFood>(new Cook(d, 10000), "c1");
cookDispatcher.AddHandler(cookQueudHandler1);
var cookQueudHandler2 = new QueuedHandler<CookFood>(new Cook(d, 5000), "c2");
cookDispatcher.AddHandler(cookQueudHandler2);
var cookQueudHandler3 = new QueuedHandler<CookFood>(new Cook(d, 100), "c3");
cookDispatcher.AddHandler(cookQueudHandler3);
var queueMonitor = new QueueMonitor(new IAmMonitored[] {cookQueudHandler1, cookQueudHandler2, cookQueudHandler3, cookQueudHandler,d.QueudHandler});
//Cook cook = new Cook(ass);
var waiter = new Waiter(d);
cookQueudHandler1.Start();
cookQueudHandler2.Start();
cookQueudHandler3.Start();
cookQueudHandler.Start();
d.Start();
alarmClock.Start();
queueMonitor.Start();
new Thread(TryPay).Start(cashier);
Random r = new Random();
for (int i = 0; i < 500; i++)
{
Guid orderNumber;
if (r.Next()%2 == 0)
{
orderNumber = waiter.PlaceDodgyOrder(new[] {Tuple.Create("Burger", 1)}, 15);
}
else
{
orderNumber = waiter.PlaceOrder(new[] { Tuple.Create("Burger", 1) }, 15);
}
if(i > 2)Thread.Sleep(2000);
orders.TryAdd(orderNumber, null);
}
//var orderNumber = waiter.PlaceOrder(new[] {Tuple.Create("Burger", 1)}, 15);
//cashier.PayForOrder(orderNumber);
Console.ReadLine();
}