When should i use ?? Timer vs Thread.Sleep(int);
-
Hi, When should i use ?? Timer vs Thread.Sleep(int); could u please guide me with justification? i believe that : I can prefer Thread.Sleep(); if my execution has to be blocked for a specific amount time, and go for Timer if i have to execute a specific job after a period. Is it like that???? Or Anything else and more important is there? please guide me.. Thanks
-
Hi, When should i use ?? Timer vs Thread.Sleep(int); could u please guide me with justification? i believe that : I can prefer Thread.Sleep(); if my execution has to be blocked for a specific amount time, and go for Timer if i have to execute a specific job after a period. Is it like that???? Or Anything else and more important is there? please guide me.. Thanks
Hi, it is slightly more complex: - you can use timers to get a single activation in future, or a periodic activation; - the timer fires its event on some thread; for a Windows.Forms.Timer that would be the main or GUI thread; for other timers, it is a different thread (which is good since it does not load the GUI thread, but it also makes you need Control.InvokeRequired and Controle.Invoke() if the timer's handler needs to touch some Control). - you can use Thread.Sleep() to put the current thread to sleep for some time, but only if that is acceptable to the thread. It is probably OK to do it in a worker thread or background thread, and not in the main thread (aka "GUI thread") since during the sleep the entire GUI comes to a halt, so it would not repaint when uncovered, you would not be able to resize it, etc etc. So, if you have things to do on the GUi thread thar must be kept apart in time, you have to organize that without Trhead.Sleep(); in that case a Windows.Forms.Timer is the right choice. :)
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/AllLanguages/General - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google
-
Hi, it is slightly more complex: - you can use timers to get a single activation in future, or a periodic activation; - the timer fires its event on some thread; for a Windows.Forms.Timer that would be the main or GUI thread; for other timers, it is a different thread (which is good since it does not load the GUI thread, but it also makes you need Control.InvokeRequired and Controle.Invoke() if the timer's handler needs to touch some Control). - you can use Thread.Sleep() to put the current thread to sleep for some time, but only if that is acceptable to the thread. It is probably OK to do it in a worker thread or background thread, and not in the main thread (aka "GUI thread") since during the sleep the entire GUI comes to a halt, so it would not repaint when uncovered, you would not be able to resize it, etc etc. So, if you have things to do on the GUi thread thar must be kept apart in time, you have to organize that without Trhead.Sleep(); in that case a Windows.Forms.Timer is the right choice. :)
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/AllLanguages/General - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google
Not fair. I wanted to answer this one;P. Good answer though.
Deja View - the feeling that you've seen this post before.
-
Not fair. I wanted to answer this one;P. Good answer though.
Deja View - the feeling that you've seen this post before.
You answered like this because it seems you have no idea about the subject.:laugh:
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
-
You answered like this because it seems you have no idea about the subject.:laugh:
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
:laugh:Yup - that's me. I'm the ultimate expert. I know nothing about everything.:laugh:
Deja View - the feeling that you've seen this post before.
-
:laugh:Yup - that's me. I'm the ultimate expert. I know nothing about everything.:laugh:
Deja View - the feeling that you've seen this post before.
Pete O`Hanlon wrote:
I know nothing about everything
Then why is it I have seen questions you did not answer ?
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/AllLanguages/General - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google
-
Pete O`Hanlon wrote:
I know nothing about everything
Then why is it I have seen questions you did not answer ?
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/AllLanguages/General - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google
I like to spread my ignorance thinly.
Deja View - the feeling that you've seen this post before.