public void Schedule1000In1ms() { var queue = new SynchronousCommandQueue(); queue.Run(); var count = 0; var reset = new AutoResetEvent(false); Action one = delegate { count++; if (count == 1000) { reset.Set(); } }; using (var thread = new ThreadPoolScheduler()) { for (var i = 0; i < 1000; i++) { thread.Schedule(i, () => queue.Enqueue(one)); } Assert.IsTrue(reset.WaitOne(1200, false)); } }
public void Start(IServiceBus bus) { _unsubscribeAction = bus.Subscribe <WorkerAvailable <T> >(Consume); // don't plan to unsubscribe this since it's an important thing bus.Subscribe(this); _threadPoolScheduler = new ThreadPoolScheduler(); _threadPoolScheduler.Schedule(_pingTimeout, _pingTimeout, PingWorkers); }
public void Timer_Based_Demo() { ThreadPoolScheduler scheduler = new ThreadPoolScheduler(); scheduler.Schedule(0, 1000, ()=> { Trace.WriteLine("Starting it up"); _ping.Start(10, _pong); }); Thread.Sleep(6000); }
public void Schedule() { var queue = new SynchronousCommandQueue(); var count = 0; var reset = new AutoResetEvent(false); Action one = () => Assert.AreEqual(0, count++); Action two = () => Assert.AreEqual(1, count++); Action three = delegate { Assert.AreEqual(2, count++); reset.Set(); }; using (var thread = new ThreadPoolScheduler()) { thread.Schedule(50, () => queue.Enqueue(three)); thread.Schedule(1, () => queue.Enqueue(one)); thread.Schedule(1, () => queue.Enqueue(two)); Assert.IsTrue(reset.WaitOne(10000, false)); } }
public void Start(IServiceBus bus) { _bus = bus; _controlBus = bus.ControlBus; _dataUri = _bus.Endpoint.Uri; _controlUri = _controlBus.Endpoint.Uri; _unsubscribeAction = bus.ControlBus.Subscribe <ConfigureWorker>(Consume, Accept); _unsubscribeAction += bus.ControlBus.Subscribe <PingWorker>(Consume); _unsubscribeAction += bus.Subscribe(this); _threadPoolScheduler = new ThreadPoolScheduler(); _threadPoolScheduler.Schedule((int)3.Seconds().TotalMilliseconds, (int)1.Minutes().TotalMilliseconds, PublishWorkerAvailability); }
public void Should_schedule_events() { Channel<UserUpdate> channel = new SynchronousChannel<UserUpdate>(); var update = new UserUpdate {LastActivity = DateTime.Now - 5.Minutes()}; CommandQueue queue = new SynchronousCommandQueue(); var scheduler = new ThreadPoolScheduler(); var future = new Future<UserUpdate>(); channel.Subscribe(queue, future.Complete); scheduler.Schedule(1000, () => channel.Publish(update)); Thread.Sleep(500); Assert.IsFalse(future.IsAvailable(0.Seconds())); Assert.IsTrue(future.IsAvailable(1.Seconds())); }
public IDisposable Schedule <TState>(TState state, Func <IScheduler, TState, IDisposable> action) { return(_normalScheduler.Schedule(state, action)); }