Beispiel #1
0
 public void TestTaskPool()
 {
     TaskPool.Shared.MaximumConcurrency = 3;
     bool fail = false;
     var cdl = new CDL(20);
     for(var i = 0; i < 20; i++)
     {
         TaskPool.Queue(t =>
         {
             fail=Interlocked.Increment(ref this.count)>3;
             Thread.Sleep(1000);
             Interlocked.Decrement(ref this.count);
             cdl.done();
         }, i);
     }
     cdl.wait();
     Assert.AreEqual(false, fail);
 }
Beispiel #2
0
 public void CDLTest()
 {
     var cdl = new CDL(100);
     for (int i = 0; i < 100; i++)
     {
         new Task<int>(() =>
         {
             Thread.Sleep(10);
             cdl.done();
             return 0;
         }).Start();
     }
     cdl.wait(50);
     Assert.IsTrue(cdl.current >= 50);
     Console.WriteLine("50->");
     cdl.wait();
     Assert.IsTrue(cdl.current == 100);
     Console.WriteLine("done->");
 }