I read C # threading handbook for less business trips a few days ago, and I still feel a lot of GAINS. Now I want to write my own experiences and see better comments.
This book covers a wide range of content. I only want to write something that I think is important but I didn't know before.
1. Thread Lifecycle
The system. Threading. Thread class provides the start, stop, suspend, resume, join, and abort thread methods. You can view the thread status through the system. Threading. threadstate attribute.
TheSuspend ()Method will suspend the current thread indefinitely until another thread wakes it up.
The effect of calling join () method is that the thread will be blocked until either the other thread completes or the time period elapses, whichever occurs first.
TheAbort ()Method wocould be very useful, if you want to terminate the thread for whatever reason.
2. Suitable and unsuitable thread locations
suitable for thread use:
. background processes
the first opportunity to spawn a new thread occurs when your application needs to run a large process in the background while still keeping its user interface active and usable.
B. accessing external resources
The second circumstance in which you might want to consider spawning a new thread occurs when you are accessing resources that are not local to your system.
not suitable for multithreading:
the first is an instance where execution order is extremely important, and the second is a mistake seen quite often in code-creating new threads in a loop.