C# exam application timer cheating issue [closed]
I have made an exam application in C# that has a timer, while taking exam suppose the candidate keeps on pressing th开发者_如何学Pythone windows' minimize button (without releasing the mouse) at 1 minute and 30 seconds, the time pauses even if the candidate keeps on pressing 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 be continued without any pauses.
What timer component are you using? System.Windows.Forms.Timer
or System.Threading.Timer
?
I suspect the S.W.F.Timer
uses SetTimer
API call which uses window messages which would explain what you are seeing, a threaded timer would be better.
You could also just use a thread, store a DateTime.UtcNow
and every 100ms or something in the thread, get another DateTime.UtcNow
and check the TimeSpan
for the elapsed time.
Use the System.Threading.Timer
class because that is supposed to work independently from windows messages
You could record the DateTime.UtcNow
when the test starts and monitor that DateTime.UtcNow - startTime
in the Elapsed
event of a timer. If the difference is greater than you want, you can end the test there.
精彩评论