First, declare the global variables and critical value TCriticalSection * CS;
// Global Zero-Boundary Value
Declare the thread in the header file or new file (actually a class)
// Download Thread class TMyThread: public TThread {public :__ fastcall TMyThread (void );
Private: virtual void _ fastcall Execute (void );
};
Set the Declaration in CPP // download the thread declarative _ fastcall TMyThread: TMyThread (void): TThread (true)
{FreeOnTerminate = true;
// This is automatic recovery of Resume ();
// This indicates execution.
Execute the code in Execute ()
}
// Download the thread execution body void _ fastcall TMyThread: Execute ()
// Thread function {CS-> Enter ();
// Various operations with critical values + If any operation is used globally, the operation is placed in the middle of the critical value. If not, the operation can be put out and executed CS-> Leave ();
// Critical value}
Enable the thread: you only need to create a NEW thread, because automatic recycle is used, so there is no recycle operation. If manual recycle is used, you must pay attention to it.
// Enable the download thread TMyThread * MyThread = new TMyThread ();
MyThread-> FreeOnTerminate = true;
Note: It is best not to use NEW or the like in the thread, because the thread is destroyed after use. So pay attention
This is an excerpt from my blog