Click here to Skip to main content
15,124,736 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello. I'm just creating a program that's supposed to count how long the computer is on. I have already created a counting of time, but there was a problem if you can save Label's content automatically when you shut down your computer (I mean that the program would save Label's value alone, without user intervention). I would be grateful for help.

What I have tried:

I am asking for help, because I have no idea how to do it.
Posted
Updated 2-May-19 2:25am

   
Comments
Member 14352515 2-May-19 7:36am
   
Thank you very much for your answer.
Instead of counting, use GetTickCount64 function (sysinfoapi.h) | Microsoft Docs[^] - it returns the milliseconds since Windows was started. It's a lot more accurate, since timers in Windows only fire "after a time period", not "on a time period". If you use timers to count seconds for example, they will drift quite significantly when the system is busy.

Remember that while WM_QUERYENDSESSION will tell you windows is about to close, it won't have any effect if the power cord is pulled out!
   
Comments
Member 14352515 2-May-19 7:36am
   
Thank you very much for your answer.
OriginalGriff 2-May-19 7:43am
   
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900