- In a timer handler (function), we should set a flag to avoid function re-entering, for example:
bool bProcessing = false;
void onTimer()
{
if (bProcessing)
return;
bProcessing = true;
// handle something.
bProcessing = false;
}
- Usually only the outermost function need add try-catch block, inner functions don't need add try-catch block. But sometimes inner function also need try-catch block so that you can do some cleanup in catch block when the exception occurs in inner function.
- If you want to check where dead loop occurs, you can click "Break All" when debugging in VS.