How would I make sure to create only a single thread on pushb开发者_JS百科utton without being accidently double-clicked?
The following code should do it (Under win32) ...
EnterCriticalSection( &critSec );
if ( ghThread != INVALID_HANDLE_VALUE )
{
ghThread = ::CreateThread( NULL, stackSize, (LPTHREAD_START_ROUTINE)ThreadEntry, NULL, 0, NULL );
}
LeaveCriticalSection( &critSec );
This does of course assume you initialise the ghThread HANDLE to INVALID_HANDLE_VALUE in advance.
Are you talking about windows programming? I'm not too familiar with that, but you should catch WM_LBUTTONDOWN message (or Double click) and set some bool flag to TRUE. And all you need is not to create thread if this flag is TRUE. It must be initialized as FALSE of cource.
精彩评论