开发者

Starting a thread on pushbutton

开发者 https://www.devze.com 2023-01-28 05:07 出处:网络
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) ...

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消