When and why should we use threads? I would like some examples.
When and why should we use threads? I would like some examples.
Keep in mind that every program already has at least one thread , which is the main thread where it is running. There are a thousand and one reasons to use thread , and every programmer should know the best occasion, but I could list a few:
We should use threads every time we need to do two tasks at the same time ...
If you have the need to gargle two lists you first load one and then load the other. With thread you can load them at the same time.
In practice when I use Threads:
In Windows forms, there is practically no way to use Multi-Thread, because any more time-consuming operation will lock the main Thread, and to access the objects of another Thread, we have to use delegates and the invoke method of the controls! p>
A good example that used Threads was to import data between different banks, where we would deploy a new system in a new company and the company had a legacy system, without using a multi-threaded system the import would last around 24h, using Thread this time dropped considerably to 35 minutes!