Multithreading is a powerful tool for creating high performance applications because they can run simultaneously on the system. Microsoft .NET gave us the facility to creating multithreaded applications. This is part one of a two-part topic. In this article we will cover the background on threading along with an example of how multiple threads can be used to improve an application's user interface. The question is this when we used threading? Simple Threads are implement when there are situations in your application in which more then one task at a time need to be completed.
There are some cons and pros of multithreading: –
Using threads the long duration tasks in application can be processed at the background or speed can be increased but Programming and debugging is more complex when you use multithreading. Threads add overhead to the system or we can say that more thread more overhead on system In order for the operating system to track a large number of threads it is going to consume processor time. If there are too many threads then each thread may not be given enough time to execute during its time execution. In addition, each thread is scheduled for execution less frequently due to the volume and time slice committed to each thread. So use thread pool every time for multithreading. In thread pool when there is any work then use of thread in thread pool otherwise send them into thread pool back.
How to use: –
To use multithreading first of all create a delegate object and then initialized this object with our method then create a new thread object using this delegate