예제 #1
0
        public void ActionTask_Simple()
        {
            var e    = new ManualResetEvent(false);
            var task = new ActionTask(() => e.Set());

            task.RecalculatePriority();

            Assert.IsTrue(task.IsRunnable);
            Assert.AreEqual(1L, task.Priority);

            using var s = PhysicalScheduler.Create();
            using var l = new LogicalScheduler(s);

            l.Schedule(task);
            e.WaitOne();
        }
예제 #2
0
        public void ActionTask_Generic_Simple()
        {
            var e    = new ManualResetEvent(false);
            var x    = default(int);
            var task = new ActionTask <int>(state => { x = state; e.Set(); }, 42);

            task.RecalculatePriority();

            Assert.IsTrue(task.IsRunnable);
            Assert.AreEqual(1L, task.Priority);

            using (var s = PhysicalScheduler.Create())
                using (var l = new LogicalScheduler(s))
                {
                    l.Schedule(task);
                    e.WaitOne();
                }

            Assert.AreEqual(42, x);
        }