title: Check if timer elapsed in thread
body: <p>I have a while loop running in my .NET backgroundworker. I would like to end the loop when Timers.Timer reaches 0. </p>
  
  <p>Problem is that since I'm working in another thread (backgroundworker), my timer has to be instantiated in that same thread. So I can't set any private boolean timer_Elapsed. Nether do I know how to give reference of boolean thro event.</p>
  
  <p><strong>Code Example:</strong></p>
  
  <pre><code>private bool timer_Elapsed = false;
  
      private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
      {
          System.Timers.Timer timer = new System.Timers.Timer();
          Set_Timer(timer);
  
          timer.Start();
  
          while(timer_Elapsed) //Has to be a boolean that indicates if timer elapsed
          {
              this.Do_Proces();
          }
      }
  
      private void Set_Timer(System.Timers.Timer timer)
      {
          timer.Interval = 200;
          timer.Elapsed += new ElapsedEventHandler(timer_ElapsedEvent);
      }
  
      private void timer_ElapsedEvent(object source, ElapsedEventArgs e)
      {
          timer_Elapsed = true; //I can't set my private boolean since it got instantiated in another thread
      }
  </code></pre>
  
  <p>Particular questions in code. I'm new with this kind of stuff.
  Any suggestions? Thanks in advance</p>
  
  <p><strong>EDIT:</strong> To clarify, I want the Do_Proces() to run for 200 milliseconds, when that time passed, I want it to stop. When it stops after 200 millisec, I want to and update GUI with data generated in backgroundWorker. Then check if user wants the proces to stop, if not, I want it to run again.. I use the timer because the thread will have to get restarted to much, this will have effect on the main thread as well, effecting the user experience badly.</p>