Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Update two progress bars simultaneously
Message
General information
Forum:
ASP.NET
Category:
Forms
Title:
Update two progress bars simultaneously
Miscellaneous
Thread ID:
01147182
Message ID:
01147182
Views:
62
I'm trying to update two progress bars simultaneosly. I created two threads, launched them to update the bars by checking if InvokeRequred amd calling Control,BeginInvoke if necessary.

I've seen in the debugger that its hitting BeginInvoke, but the bars still seem to be updating one after the other. I've tried putting a sleep to slow things down.

Is there a better way to set this up?
Thread newThread1 = new Thread(
            new ThreadStart(this.Meter1));
            
            Thread newThread2 = new Thread(
            new ThreadStart(this.Meter2));

            newThread1.Start();
            newThread2.Start();

 private void  Meter1()
        {

            if (pbMeter1.InvokeRequired)
            {
                IAsyncResult result = pbMeter1.BeginInvoke(new MethodInvoker(this.Meter1));
                while (!result .IsCompleted )
                {
                    Thread.Sleep(100);
                }
                pbMeter1.EndInvoke(result);

            }
            else
            {
                for (int i = 0; i < 10000; i++)
                {

                    pbMeter1.Value = i;
                }
            }
             
        }

        private void Meter2()
        {
            if (pbMeter2.InvokeRequired)
            {
               IAsyncResult result = pbMeter2.BeginInvoke(new MethodInvoker(this.Meter2));

                while (!result.IsCompleted)
                {
                    Thread.Sleep(100);
                }
                pbMeter2.EndInvoke(result);

            }
            else
            {
                for (int i = 0; i < 10000; i++)
                {
                    pbMeter2.Value = i;
                }
            }
        }
Regards,

E.R. Gilmore
Next
Reply
Map
View

Click here to load this message in the networking platform