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
Titre:
Update two progress bars simultaneously
Divers
Thread ID:
01147012
Message ID:
01147012
Vues:
93
This is for a class lab.

I have to progress bars and I have created two threads that use a delegate back to the UI thread to update the progress bars. But they still update sequentially. How do I get them to update at the same time?
namespace MultiThreadLab
{
    public partial class Form1 : Form
    {
        delegate void SetMeterCallback();

        //delegate void SetMeter2Callback();

        public Form1()
        {
            InitializeComponent();
        }

        private void cmdStart_Click(object sender, EventArgs e)
        {
            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)
                {
                    SetMeterCallback d = new SetMeterCallback(Meter1);
                    this.BeginInvoke(d, null );
                }
            else
            {            
                for (int i = 0; i < 10000; i++)
                {
                    pbMeter1.Value = i;              
                }
            }
        }

        private void Meter2()
        {
            if (pbMeter2.InvokeRequired)
            {
                SetMeterCallback d = new SetMeterCallback(Meter2);
                this.BeginInvoke(d, null);
            }
            else
            {
                for (int i = 0; i < 10000; i++)
                {
                    pbMeter2.Value = i;
                }
            }
        }
    }
}
Regards,

E.R. Gilmore
Répondre
Fil
Voir

Click here to load this message in the networking platform