Click here to Skip to main content
13,000,982 members (61,581 online)
   

C#

 
AnswerRe: How to read out whole static text present on external application's Input boxes or message boxes in C# Pin
Gerry Schmitz19-Feb-13 20:27
memberGerry Schmitz19-Feb-13 20:27 
GeneralRe: How to read out whole static text present on external application's Input boxes or message boxes in C# Pin
sham bhand21-Feb-13 4:48
membersham bhand21-Feb-13 4:48 
GeneralRe: How to read out whole static text present on external application's Input boxes or message boxes in C# Pin
Gerry Schmitz21-Feb-13 8:40
memberGerry Schmitz21-Feb-13 8:40 
Question[SOLVED] Not Getting CPU Usage Pin
AmbiguousName18-Feb-13 18:51
memberAmbiguousName18-Feb-13 18:51 
QuestionC# run a process Pin
classy_dog18-Feb-13 7:02
memberclassy_dog18-Feb-13 7:02 
AnswerRe: C# run a process Pin
Eddy Vluggen18-Feb-13 7:48
mvpEddy Vluggen18-Feb-13 7:48 
GeneralRe: C# run a process Pin
classy_dog18-Feb-13 8:22
memberclassy_dog18-Feb-13 8:22 
GeneralRe: C# run a process Pin
Eddy Vluggen18-Feb-13 8:30
mvpEddy Vluggen18-Feb-13 8:30 
GeneralRe: C# run a process Pin
classy_dog18-Feb-13 14:04
memberclassy_dog18-Feb-13 14:04 
GeneralRe: C# run a process Pin
Eddy Vluggen18-Feb-13 22:31
mvpEddy Vluggen18-Feb-13 22:31 
GeneralRe: C# run a process Pin
classy_dog19-Feb-13 5:38
memberclassy_dog19-Feb-13 5:38 
GeneralRe: C# run a process Pin
Eddy Vluggen19-Feb-13 9:34
mvpEddy Vluggen19-Feb-13 9:34 
QuestionThread.Sleep is NOT evil Pin
devvvy18-Feb-13 5:55
memberdevvvy18-Feb-13 5:55 
AnswerRe: Thread.Sleep is NOT evil Pin
Pete O'Hanlon18-Feb-13 6:15
protectorPete O'Hanlon18-Feb-13 6:15 
devvvy wrote:
Thread.Sleep is one-line of code, simple, and get the job done

Just because it's simple to implement, this doesn't mean it's a good choice. I recommend against Thread.Sleep precisely because of what it does - it suspends a thread for a timeout period. That doesn't seem too bad if you want to wait for a period, but the big problem comes when you want to terminate that thread. When a thread is sleeping, terminating it isn't easy - effectively, you have to wait for the thread to wake up just to kill it. This may not seem to be too big a deal, but if your system relies on having a number of these internally, you have just forced the user to wait and that's generally not a good thing.

The primary reason that I recommend against it is precisely because it's so easy to use. The problem is, people end up using it as a blunt object and force it into programs that it shouldn't be in, precisely because they don't understand the downsides. If you fully appreciate the tradeoffs in Thread.Sleep then, by all means, use it. Don't, however, put it into code that a noob is going to read - as they probably don't appreciate the underlying issues with Thread.Sleep then they will blindly use it.

There are other, subtle, problems with the use of Thread.Sleep, with relation to priority. A simple pattern, though, is simply to use Monitor.Enter to control the access, and this is my preferred choice in a lot of cases.
I was brought up to respect my elders. I don't respect many people nowadays.

CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

GeneralRe: Thread.Sleep is NOT evil Pin
devvvy18-Feb-13 13:29
memberdevvvy18-Feb-13 13:29 
GeneralRe: Thread.Sleep is NOT evil Pin
N a v a n e e t h18-Feb-13 16:12
memberN a v a n e e t h18-Feb-13 16:12 
GeneralTHANK YOU - this is the answer I was looking for. Pin
devvvy19-Feb-13 12:53
memberdevvvy19-Feb-13 12:53 
GeneralRe: Thread.Sleep is NOT evil Pin
Pete O'Hanlon18-Feb-13 20:43
protectorPete O'Hanlon18-Feb-13 20:43 
GeneralApplication Exit vs Thread.Abort? Pin
devvvy19-Feb-13 13:12
memberdevvvy19-Feb-13 13:12 
GeneralRe: Thread.Sleep is NOT evil Pin
Simon_Whale18-Feb-13 13:41
memberSimon_Whale18-Feb-13 13:41 
GeneralRe: Thread.Sleep is NOT evil Pin
N a v a n e e t h18-Feb-13 16:15
memberN a v a n e e t h18-Feb-13 16:15 
GeneralRe: Thread.Sleep is NOT evil Pin
devvvy19-Feb-13 1:41
memberdevvvy19-Feb-13 1:41 
GeneralRe: Thread.Sleep is NOT evil Pin
Pete O'Hanlon19-Feb-13 2:18
protectorPete O'Hanlon19-Feb-13 2:18 
GeneralRe: Thread.Sleep is NOT evil Pin
N a v a n e e t h19-Feb-13 6:33
memberN a v a n e e t h19-Feb-13 6:33 
GeneralRe: Thread.Sleep is NOT evil Pin
devvvy19-Feb-13 12:47
memberdevvvy19-Feb-13 12:47 
GeneralRe: Thread.Sleep is NOT evil Pin
devvvy19-Feb-13 12:35
memberdevvvy19-Feb-13 12:35 
GeneralRe: Thread.Sleep is NOT evil Pin
Pete O'Hanlon19-Feb-13 13:06
protectorPete O'Hanlon19-Feb-13 13:06 
GeneralApplication exit: Valid concern for SCENARIO 2 from Pete (Big thank you!) Pin
devvvy19-Feb-13 13:30
memberdevvvy19-Feb-13 13:30 
GeneralRe: Thread.Sleep is NOT evil Pin
N a v a n e e t h19-Feb-13 6:36
memberN a v a n e e t h19-Feb-13 6:36 
GeneralRe: Thread.Sleep is NOT evil Pin
devvvy19-Feb-13 12:36
memberdevvvy19-Feb-13 12:36 
AnswerRe: Thread.Sleep is NOT evil Pin
Dave Kreskowiak18-Feb-13 15:52
mvpDave Kreskowiak18-Feb-13 15:52 
GeneralRe: Thread.Sleep is NOT evil Pin
devvvy19-Feb-13 1:38
memberdevvvy19-Feb-13 1:38 
GeneralRe: Thread.Sleep is NOT evil Pin
Dave Kreskowiak19-Feb-13 1:46
mvpDave Kreskowiak19-Feb-13 1:46 
GeneralRe: Thread.Sleep is NOT evil Pin
devvvy19-Feb-13 1:49
memberdevvvy19-Feb-13 1:49 
GeneralRe: Thread.Sleep is NOT evil Pin
Dave Kreskowiak19-Feb-13 2:19
mvpDave Kreskowiak19-Feb-13 2:19 
GeneralRe: Thread.Sleep is NOT evil Pin
devvvy19-Feb-13 12:38
memberdevvvy19-Feb-13 12:38 
GeneralRe: Thread.Sleep is NOT evil Pin
Dave Kreskowiak19-Feb-13 14:03
mvpDave Kreskowiak19-Feb-13 14:03 
GeneralRe: Thread.Sleep is NOT evil Pin
devvvy19-Feb-13 14:07
memberdevvvy19-Feb-13 14:07 
AnswerRe: Thread.Sleep is NOT evil Pin
GuyThiebaut18-Feb-13 21:49
memberGuyThiebaut18-Feb-13 21:49 
GeneralRe: Thread.Sleep is NOT evil Pin
Pete O'Hanlon18-Feb-13 22:35
protectorPete O'Hanlon18-Feb-13 22:35 
GeneralRe: Thread.Sleep is NOT evil Pin
GuyThiebaut18-Feb-13 23:17
memberGuyThiebaut18-Feb-13 23:17 
GeneralRe: Thread.Sleep is NOT evil Pin
devvvy19-Feb-13 1:45
memberdevvvy19-Feb-13 1:45 
GeneralRe: Thread.Sleep is NOT evil Pin
Pete O'Hanlon19-Feb-13 2:03
protectorPete O'Hanlon19-Feb-13 2:03 
GeneralRe: Thread.Sleep is NOT evil Pin
devvvy19-Feb-13 12:44
memberdevvvy19-Feb-13 12:44 
GeneralRe: Thread.Sleep is NOT evil Pin
Pete O'Hanlon19-Feb-13 13:13
protectorPete O'Hanlon19-Feb-13 13:13 
GeneralRe: Thread.Sleep is NOT evil Pin
devvvy19-Feb-13 13:32
memberdevvvy19-Feb-13 13:32 
GeneralRe: Thread.Sleep is NOT evil Pin
GuyThiebaut19-Feb-13 2:07
memberGuyThiebaut19-Feb-13 2:07 
GeneralRe: Thread.Sleep is NOT evil Pin
devvvy19-Feb-13 12:41
memberdevvvy19-Feb-13 12:41 
GeneralRe: Thread.Sleep is NOT evil Pin
BobJanova18-Feb-13 23:56
memberBobJanova18-Feb-13 23:56 
GeneralRe: Thread.Sleep is NOT evil Pin
Pete O'Hanlon19-Feb-13 0:02
protectorPete O'Hanlon19-Feb-13 0:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web02 | 2.8.170624.1 | Last Updated 25 Jun 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid