It sounds like the second click is getting queued in a buffer somewhere, thats why I say have you looked at subclassing the procedure?
Another way might be to disable the loop code upon return from the loop for a few seconds using the window timer so the second click in the queue cant trigger the button code again?
I would make a 2nd button that’s HIDE and does the real processing. You’ll see this type thing with Browse NewSelection and Window Resize with Event:DoReszie.
OF ?ProcessBtn
IF ~DoProcessing AND ?{PROP:Enabled} THEN !prevent click twice
IF KEYCODE()=MouseLeft2 THEN CYCLE. !This is THE problem, fast clicking throws a 2nd Accepted with KeyCode Left2
DoProcessing = TRUE
DISABLE(?)
POST(EVENT:Accepted,?Processing_Hidden_Btn)
Yield()
END
OF ?Processing_Hidden_Btn
IF ~DoProcessing THEN CYCLE. !Should never happen
DO Longgggg_Process
DoProcessing = FALSE
ENABLE(?ProcessBtn)
Not sure above would fix, was not tested. See post 22 below for a simpler time check method that was solution:
the time window for this to happen is tiny, but perhaps wrap all access to CanRun in a critical section to be safe.
or that would probably work too. But critical section would be safest. Also with critical section the flag could safely be global in case it was done in more than one thread.
The code is Not running in 2 threads so I cannot see a CS doing anything.
The OP says the user is getting 2 button click events posted quickly, i.e. in the message queue. I wonder if the 2nd one has a double click KeyCode Mouse Left 2