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?

    1 answer 1

    The result of WaitForSingleObject () will exactly correspond to the status of the stream: WAIT_OBJECT_0 - the stream ended, WAIT_TIMEOUT - the stream is active, but the Wait-function waited for the specified time and exited.

    • Thank you very much! Missed MSDN ... - Iceman
    • one
      @Iceman there is not clearly written, IMHO - Vladimir Martyanov