Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to run Multiple threads
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01213236
Message ID:
01215310
Vues:
16
Hi Einar,

Your first code example works with an extra line or two of code more than mine. However, I feel that having to wire up the events to achieve your solution is more cryptic than simply calling the Thread.Start() method specifying the delegate method. Also, my approach allows for the methods specified as delegates to the Thread.Start() method to actually be called directly. In otherwords, you could easily call:-
prog.Method1() 
prog.Method2()
As you are using events, whilst it is technically possible,
bw1_DoWork(null, new DoWorkEventArgs(1)) 
bw2_DoWork(null, new DoWorkEventArgs(2)) 
is far from ideal.

Your second code example actually "misses the mark" because it actually calls the same loop over and over but simply passes a different numeric argument in via the EventArgs parameter. You have obviously achieved a similar visual effect to the console window but this comes from only one method. My original code actually runs two separate methods each on their own separate thread that just happen to output to the same console window. Also, your second code example would need to be synchronized to provide any kind of data integrity and as such, any synchronization/lock would block the waiting thread. Obviously, this would defeat the point of spawning two threads in the first place.

Cheers

-=Gary
-=Gary
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform