A few events are raised rapidly from the same thread where the handler is, I want this handler to process only one event (doesn't matter which one).
Since it's all in one thread, I can't use lock or other technique for multi-thread sync, so I simply use a bool flag, like so:
It seems though that this handler can be called while the first call is still checking and setting the flag, is there a safer solution?
Since it's all in one thread, I can't use lock or other technique for multi-thread sync, so I simply use a bool flag, like so:
C#:
bool busy = false;
static internal readonly EventHandler ClickHandler = (object? sender, EventArgs e) =>
{
if (busy) return;
busy = true;
//...
};
It seems though that this handler can be called while the first call is still checking and setting the flag, is there a safer solution?