Understanding processes, threads, and tasks
A process, for example, each of the console applications we have created has resources allocated to it, such as memory and threads. A thread executes your code, statement by statement. By default, each process only has one thread, and this can cause problems when we need to do more than one task at the same time.
Windows and most other modern operating systems use preemptive multitasking, which simulates the parallel execution of tasks. It divides the processor time among the threads, allocating a "time slice" to each thread one after another. The current thread is suspended when its time slice finishes. The processor allows another thread to run for a time slice.
When Windows switches from one thread to another, it saves the context of the thread and reloads the previously saved context of the next thread in the thread queue. This takes time and resources.
Threads may have to compete for, and wait for access to, shared resources, such...