Threads in C#
Threads are a concept that allows computers to seem to be doing more than one thing at once in your program. Just as an OS allows multiple programs to run simultaneously, threads allow your program to run multiple flows in your application concurrently. A thread is nothing more than an execution flow in your program. You always have at least one thread: the one that got started when the program began its execution. We call this the main thread. The runtime manages this thread and you have little control over it. All the other threads, however, are yours, and you can do whatever you want with them.
Threads are nothing magical. The basic principle is quite easy:
- Create a method, function, or any other piece of code you want to run.
- Create a thread, giving it the address of the method.
- Start the thread.
- The OS or runtime executes that method or function while running the main thread simultaneously.
- You can monitor the progress of that thread. You...