.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Articles >> C# >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Advantage of Threading demonstrated

Posted By:Jean Paul       Posted Date: September 30, 2010    Points: 25    Category: C#    URL: http://www.dotnetspark.com  

In this article I am trying to show the advantage of using Threading to reduce the waiting time by 90%.


Threading can be useful in a scenario where one operation is depending on some network delays or user inputs.
Such scenario can take advantage of using Threads.

About Code
The example tries to show the difference of a lengthy process execution.

The Task class contains a Perform method which requires 1 second to complete.
This operation was called 10 times without Thread and with Thread.

1) Without Thread case it took 10 seconds to complete as the main thread is waiting for each operation
   to be completed

2) With Thread case took only 1 second for the completion (90% time reduced) as each subsequent
operations continued without waiting for the other operations.

Examples of Time Consuming Operation
1) Web Services
2) User Prompt Dialog
3) Parsing of a web site
4) Waiting for another computer to respond

Threading can be advantageous in the above mentioned scenario.  It should be noted that
if the same processor cycles are used for a method to work on and we convert that
operations into a threaded manner the entire process will become slow.

So threading is not advantageous if all the operations are carried out in the same machine.
Here more synchronizing cycles will be wasted.

So wise use of threading is recommended.


 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend