function CreateThread(
lpThreadAttributes: Pointer;
dwStackSize: DWORD;
lpStartAddress: TFNThreadStartRoutine;
lpParameter: Pointer;
dwCreationFlags: DWORD; {启动选项}
var lpThreadId: DWORD
): THandle; stdcall;
CreateThread's penultimate parameter dwcreationflags (startup option) has two optional values:
0: Execute the entry function immediately after the thread is established;
Create_suspended: The thread is set up to suspend the wait.
The available ResumeThread function is the operation of the recovery thread; Use SuspendThread to suspend the thread again.
The arguments for both functions are thread handles, and the return value is the pending count before execution.
What is a hang count?
SuspendThread will give this number +1; ResumeThread will give this number-1; But the smallest number is 0.
When this number = 0 o'clock, the thread will run; > 0 o'clock will hang up.
If you are suspendthread multiple times, you also need to resumethread multiple times to restore the thread's operation.
In the following example, a new thread keeps assigning random values to a global variable;
The Timer control on the form then writes the variable to the form title every 1/10 seconds;
In this process, ResumeThread, suspendthread two functions were demonstrated.
Run Effect chart: