title: Animate Loading in WPF C#
body: <p>I have button on my window. After user <strong>clickes</strong> the button i want my <strong>application to animate loading label (with rotationg it), during the other thread gets some data from database</strong>. <strong>After loading data from DB animation must end</strong>. The task seems simple , but it doesn't work.
  The problem is that animation whatever i do animation starts only after loading from the database when it is not needed.</p>
  
  <p><em>Help please. Here some code:</em></p>
  
  <pre><code>private void LoginButtonClick(object sender, RoutedEventArgs e)
  { 
    Thread thread = new Thread(new ThreadStart(
      delegate()
      {
        DispatcherOperation dispatcherOp =
          this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(
            delegate()
            {
              var da = new DoubleAnimation(360, 0, new Duration(TimeSpan.FromSeconds(1)));
              var rt = new RotateTransform();
              loadingLabel.RenderTransform = rt;
              loadingLabel.RenderTransformOrigin = new Point(0.5, 0.5);
              da.RepeatBehavior = RepeatBehavior.Forever;
              rt.BeginAnimation(RotateTransform.AngleProperty, da);
            }));
        dispatcherOp.Completed += new EventHandler(DispatcherOpCompleted);
      }));
    thread.Start();
  }
  
  void DispatcherOpCompleted(object sender, EventArgs e)
  {
    //Loading From Database
  }
  </code></pre>