✅ best way to snooze winforms
I have a win forms app with a snooze button, once the snooze button is clicked i need to make the form disappear and make it appear after 30 mins and rn I'm doing a form.hide and thread.sleep(30 mins in millisecs). Is this the right way or is there anything else i can do here?
12 Replies
thread.sleep bad, use a timer with a callback to show the form again
otherwise you're blocking your form's thread for 30 minutes and if a message comes in for it to process it won't be able to
Right, although in my case nothing will happen in 30 mins but i want to use best practices.
How do i get started with timer?
you won't do anything in 30 minutes, but there are other things happening in the background to make the window "work"
Timer Class (System.Timers)
Generates an event after a set interval, with an option to generate recurring events.
there are multiple types of timer but this one should work for what you're doing
Thank you, imma look into it 🙂
basically sleeping your main thread for that long will make the form look like it's not responding
Right I'm hiding it before sleeping it tho
I get what you're saying
i mean the OS will also think it's not responding if you look at the process in task manager or something
Righttt, gotcha in task manager it might say not responding/ suspended
And user might kill it too
I concur timer is the right way to go
Thanks guys, i did some researching and made it work