Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2325
How to use activity indicator?
posted

We have a form that is used for display purposes and does not require any user intervention other than closing it.   I have a timer that fires off after the form is loaded to run a process that basically calls a stored proc that does some stuff on the database.  I would like to have the activity indicator to be active while this is happening. 

In my constructor I have the following:


            ultraActivityIndicator1.AnimationEnabled = true;
            ultraActivityIndicator1.AnimationSpeed = 20;

I tried putting the code in the timer_tick event like this:

        void myTimer_Tick(object sender, EventArgs e)
        {
            myTimer.Enabled = false;
            ultraActivityIndicator1.Start(true);

            ComputeServices();

            ultraActivityIndicator1.Stop();
            ultraActivityIndicator1.Visible = false;
            
            InitFormStuff();
        }

However the indicator doesnt do anything... how do I get this to work?

thanks!

Parents
No Data
Reply
  • 4625
    Verified Answer
    Offline posted

    Hello Jeff,

    Thank you for posting in our forums!

    Based on the provided code snippet, I believe UltraActivityIndicator control and the ComputeServices method are using the same Thread – the main UI thread. This might be the reason while your time consuming work is executed, the UltraActivityIndicator UI thread to be frozen and not active.

    Therefore you might want to create a new thread for the work executed in the background of your form. This will allow the execution of the two tasks at the same time, without interrupting each other.

    You may find the following articles related to multithreading useful:
    The Basics of Task Parallelism via C#
    How to: Make Thread-Safe Calls to Windows Forms Controls

    Also I have created a sample for you, which shows active UltraActivityIndicator animation, until the work at the background is being done.

    I am waiting for your response.

    WinActivityIndicatorSample.zip
Children