public void Resume_ResumesWaitingTasks()
        {
            long[] token = { 0 };
            using(var controller = new ThreadController())
            {
                controller.Add(c => { Thread.Sleep(10); c.Wait(); Interlocked.Increment(ref token[0]); });
                controller.Add(c => { Thread.Sleep(10); c.Wait(); Interlocked.Increment(ref token[0]); });
                controller.Add(c => { Thread.Sleep(10); c.Wait(); Interlocked.Increment(ref token[0]); });

                controller.Start();
                controller.Pause();

                Assert.That(Interlocked.Read(ref token[0]), Is.EqualTo(0));

                controller.Resume();

                Thread.Sleep(50);
                Assert.That(Interlocked.Read(ref token[0]), Is.EqualTo(3));

                controller.Stop();
            }
        }
        public void Resume_ResumesWaitingTasks()
        {
            long[] token = { 0 };
            using (var controller = new ThreadController())
            {
                controller.Add(c => { Thread.Sleep(10); c.Wait(); Interlocked.Increment(ref token[0]); });
                controller.Add(c => { Thread.Sleep(10); c.Wait(); Interlocked.Increment(ref token[0]); });
                controller.Add(c => { Thread.Sleep(10); c.Wait(); Interlocked.Increment(ref token[0]); });

                controller.Start();
                controller.Pause();

                Assert.That(Interlocked.Read(ref token[0]), Is.EqualTo(0));

                controller.Resume();

                Thread.Sleep(50);
                Assert.That(Interlocked.Read(ref token[0]), Is.EqualTo(3));

                controller.Stop();
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Resumes schedule polling.
 /// </summary>
 public void Resume()
 {
     _controller.Resume();
 }