C # exam application timer problem

I made a C # exam application that has a timer, and taking the exam, assume that the candidate continues to click the minimize button (without releasing the mouse) after 1 minute and 30 seconds, the time pauses, even if the candidate continues to press the mouse for 10 minutes, but when the mouse is released, the time resumes from the very second where it was paused, i.e. 1 minute and 30 seconds. I want the timer to continue without pauses.

+6
source share
3 answers

Which timer component are you using? System.Windows.Forms.Timer or System.Threading.Timer ?

I suspect that SWFTimer uses the SetTimer API call, which uses window messages that would explain what you see, it would be better to use a thread timer.

You can also just use the stream, save DateTime.UtcNow and every 100 ms or something in the stream, get another DateTime.UtcNow and check the TimeSpan for the elapsed time.

+4
source

Use the System.Threading.Timer class because it should work regardless of Windows messages

+2
source

You can write DateTime.UtcNow when testing starts, and note that DateTime.UtcNow - startTime in the Elapsed timer event. If the difference is greater than you want, you can finish the test there.

+1
source

Source: https://habr.com/ru/post/895740/


All Articles