Exemplo n.º 1
0
 public static void ThreadBody()
 {
     while (true)         // run so long as initiator exists.
     {
         if (TerminateBackgroundThread == true)
         {
             break;       // terminates this thread if initiator is removed
         }
         done = false;
         if (BackgroundHelper.IsRisingEdge(doSomething, ref doSomething))
         {
             int a = 0;
             int b = 1;
             int n = 300000;
             // If something is to do we do this.
             // Example: In N steps compute Fibonacci sequence iteratively .
             for (int i = 0; i < n; i++)
             {
                 int temp = a;
                 a = b;
                 b = temp + b;
             }
             done = true; // Initiator of this thread looks on this bit to detect the job has been done.
         }
         else
         {
             // Pause for a moment to provide a delay to make
             // threads more apparent.
             Thread.Sleep(100);
         }
     }
 }
Exemplo n.º 2
0
        public void __Process()
        {
            if (BackgroundHelper.IsRisingEdge(startThread, ref m_startThread))
            {
                done = false;
                BackgroundServerThread.doSomething = true;
            }
            done = BackgroundServerThread.done;

            if (BackgroundHelper.IsFallingEdge(startThread, ref m_startThread))
            {
                BackgroundServerThread.doSomething = false;
                done        = false;
                startThread = false;
            }
        }