Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to run Multiple threads
Message
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01213236
Message ID:
01215310
Views:
15
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform