Exemplo n.º 1
0
 public void ReceiveToken(DetectionToken token)
 {
     Console.WriteLine("Receiving token: Color={0},Counter={1}", token.Color, token.Counter);
     lock (TokenLocker)
     {
         Console.WriteLine("Lock acquired.");
         Thread.VolatileWrite(ref HoldingToken, 1);
         MyToken = token;
         if (Thread.VolatileRead(ref PendingMessageCount) == 0)
         {
             Task.Factory.StartNew(() =>
                                   ProcessToken());
         }
         else
         {
             Console.WriteLine("Still busy, pending message count = {0}", PendingMessageCount);
         }
     }
 }
Exemplo n.º 2
0
 public AsyncTerminationDetector()
 {
     if (Global.MyPartitionId == 0)
     {
         MyToken = new DetectionToken
         {
             Color   = (int)ATDColor.White,
             Counter = 0//for the ignition message
         };
         HoldingToken = 1;
     }
     else
     {
         HoldingToken = 0;
     }
     //Task.Factory.StartNew(() =>
     //    {
     //        while (true)
     //        {
     //            Thread.Sleep(1000);
     //            Console.WriteLine("Current pending job count = {0}", PendingMessageCount);
     //        }
     //    });
 }