Multi-threaded applications and multi-threaded Application Design
We are used to executing some additional time-consuming operations in a single thread, or performing operations on tasks that may impede other tasks. through the rational use of multiple threads, allows the client to get a faster response. By using separate threads to execute CPU-intensive and IO-intensive jobs, the user interface remains active. Of course, everything has two sides. Improper handling will lead to thread security issues.
Create and use threads
We often use the new keyword to create a thread. Below are some common thread methods.
// Create thread var Thread = new thread () => Console. writeLine (); // start thread. start (); // terminate thread. abort (); # The region method is out of date // suspends the thread. suspend (); // resume the suspended thread. resume (); # The endregion method is out of date.
Thread attributes
Some common attributes.
// Thread priority // thread. priority // thread status // thread. threadState // thread execution status // thread. isAlive // whether it is a background thread // thread. isBackground // thread name // thread. name
Thread priority
The CPU allocates a longer period of time to threads with higher priority.
Background thread
The background thread stops immediately after the last foreground thread stops.
Https://docs.microsoft.com/zh-cn/dotnet/csharp/programming-guide/concepts/threading/multithreaded-applications (reference)