![]() No manual updating of fields - saves code and threading headaches and you could go for a "real" (=threaded) timer approach. Or, have your pc go to sleep, or restart after a while. If you use WPF you should really use binding and not code-behind. This ultra-small app shuts your computer off automatically after a given period (max. ![]() Bonus: This way you can make your timer intervall shorter than one second and get a more "smooth" time display.ģ. WIth just a few clicks, you can schedule these actions with ease. Sleep: Select how long you want your device to wait before going to sleep when youre not using it. PowerScheduler is a lightweight app that allows you to set a custom timer that will sleep, Restart, Hibernate, Lock, Log Off, and Shut Down of your PC. Screen: Select how long you want your device to wait before turning the screen off when youre not using your device. Why?: Gui-Timer-Events will be thrown away if not processed between ticks, so in your app it can happen that the timer doesn't "see" a tick for some intervalls and your "time calculation" goes wrong. To adjust power and sleep settings in Windows 11, select Start > Settings > System > Power & battery > Screen and sleep. ![]() Better: Store the "start time" and get the current time inside timer tick, than calculate difference between start time and current system time and apply your math. If you calculate the "elapsed time" in your timer tick - so you can update the GUI - never use the tick-Intervall for calculations (your timeleft variable (should be named secondsleft.). Even worse in a WPF app a Systems Windows forms timer.Ģ. So I feel you could need some tips (maybe for your next app?)ġ. But you use a fundamentally wrong approach. For your purpose and desired accuracy it seems ok. The only thing I quickly recognized was the "missuse" of a timer.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |