title: How to wait until Timer stops?
body: <p>I'm trying to build a blackjack game using C#.
  I have a casino class and player , card and deck classes which are objects of casino.
  Casino deals a random card to a player with the function:</p>
  
  <pre><code>        public void giveRandomCardTo(Player P)
          {
              P.takeCard(this.deck.getRandomCard());
          }
  </code></pre>
  
  <p>this works nicely, but then I wanted to add an animation, like a closed card image moves to the player's card picturebox, using a timer. So I added this part to the function:</p>
  
  <pre><code>public void giveRandomCardTo(Player P)
          {
              while (_timerRunning) {/*wait*/ }
              this.currentDealingID = P.id;
              if (this.currentDealingID &gt;= 0 &amp;&amp; this.currentDealingID &lt; this.NumberOfPlayers &amp;&amp; this.currentDealingID!=10) 
              {//Checking the current player is not the dealer.
                  this.MovingCard.Show(); //Moving card is a picture box with a closed card
                  _timerRunning=true;
                  T.Start();
              }
              P.takeCard(this.deck.getRandomCard());    
          }
  </code></pre>
  
  <p>and the Timer.Tick eventhandler of Timer T is:</p>
  
  <pre><code>public void TimerTick(object sender, EventArgs e)
  {
                movingcardvelocity = getVelocityFromTo(MovingCard.Location, this.Players[this.currentDealingID].CardPBS[0].Location);
                double divide=5;
                movingcardvelocity = new Point((int)(movingcardvelocity.X / divide), (int)(movingcardvelocity.Y / divide));
                this.MovingCard.Location = new Point(this.MovingCard.Location.X + movingcardvelocity.X, this.MovingCard.Location.Y + movingcardvelocity.Y);
  //Stop if arrived:
                double epsilon = 20;
                if (Distance(this.MovingCard.Location, this.Players[this.currentDealingID].CardPBS[0].Location) &lt; epsilon) 
      {
      _timerRunning=false;  
      this.MovingCard.Hide();
      T.Stop();
      }
  }
  </code></pre>
  
  <p>Timer works nicely, too. But when I'm dealing cards one after another, I have to wait until the first animation finishes. And the line <code>while(_timerRunning){/*wait*/}</code> in <code>void giveRandomCardTo</code> stucks the program in an infinite loop.</p>
  
  <p>How can I make it wait until <code>bool _timerRunning = false</code>?</p>
  
  <p>Thanks for any help.</p>