Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6910497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:49:19+00:00 2026-05-27T08:49:19+00:00

I have button on my window. After user clickes the button i want my

  • 0

I have button on my window. After user clickes the button i want my application to animate loading label (with rotationg it), during the other thread gets some data from database. After loading data from DB animation must end. 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.

Help please. Here some 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
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:49:20+00:00Added an answer on May 27, 2026 at 8:49 am

    The Dispatcher.Completed event is executed on the main UI thread. Your worker thread is just queueing the dispatcher operation and exiting. Instead of creating a thread that starts the animation and then doing your database loading in the Completed handler, just start your animation in the main thread, and then create a worker thread to do the database loading.

    private void LoginButtonClick(object sender, RoutedEventArgs e)
    {
      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);
    
      Thread thread = new Thread(new ThreadStart(LoadData));
      thread.Start();
    }
    
    void LoadData()
    {
      //Loading From Database
    
      // Use a Dispatch.BeginInvoke here to stop the animation
      // and do any other UI updates that use the results of the database load
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After the user clicks on....log in button, and other events, I made a loading
I have a button on the window form and and one method I am
I would like to have a button in my window such that if I
I have a Switch to window button on my main form that I'd like
I have a button with a transparent background on a wpf window. Problem is,
I have a button that opens a panel in a popup window and then
I load a single instance of a window on php-gtk, I have a button
I have a login window with a Sign In button which is set as
I have a WPF window, which contains a button called Cancel. Under ordinary circumstances
I have 4 buttons on a page. Each button opens a modal window and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.