1. Sleep and Interrupt
The Sleep function blocks the current thread for a certain period of time. When the time arrives, the operating system continues scheduling and execution in the next time slice according to its scheduling algorithm.
The Interrupt function wakes up a thread in the WaitSleepJoin state. Essentially, the Interrupt function triggers ThreadInterryptedException to a thread in the WaitSleepJoin State. If the exception is not handled, it will continue to be thrown up,
Therefore, a best practice for writing multi-threaded programs is to use the try-catch Block in the main function of the thread to capture all possible exceptions.
2. Background thread and foreground thread
The IsBackground attribute control thread of a thread is a front-end thread or background thread. The front-end thread is only a little different from the background thread, and the background thread will not stop terminating. If all foreground threads of a process terminate, CLR ends the process, and other background running threads are also forcibly terminated without waiting for execution to complete.
3. Suspend and Resume
Suspend and Resume are two obsolete functions. The Suspend function converts the thread to the suincluded state, and the Resume function converts the thread from the suincluded state to the running state.
From Enjoy. NET