The stream starts the function of checking the need to create a VPN connection, which, if a VPN is needed, runs for a long time. To reduce the waiting time, the waiting time for the thread is set to 3 seconds, after which it is necessary to check if the thread is still running, and if so, nail it down and assign the desired value to the variable.
Code:
DWORD ThreadId; HANDLE CheckAddressThread = CreateThread(NULL, 0, NeedVPN, NULL, 0, &ThreadId); WaitForSingleObject(CheckAddressThread, 3000); if(/*CheckAddressThread всё ещё отрабатывает...*/){ TerminateThread(CheckAddressThread, 0); RequiredVPN = 1; } CloseHandle(CheckAddressThread); if(RequiredVPN){... How to check if the stream is working?