Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Update two progress bars simultaneously
Message
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Divers
Thread ID:
01147182
Message ID:
01147211
Vues:
28
Hi,

I'm confused. Given that they can't be actually updated siumultaneously (only consecutively) then surely using seperate threads and asynchronous method calls are two things that will help guarantee failure?

Regards,
Viv

>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;
>                }
>            }
>        }
>
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform