Prev: 2-dimensional array
Next: This might seems like a strange question but a Thread can'r run if the main Thread stops
From: Patrice on 17 May 2010 13:52 Thanks for the details about how it works... The problem I alluded is that I've seen very often BackgroundWorker test code calling back the UI thread in a tight loop and using a significant value in a Sleep call supposed to simulate some processing giving significantly more time to the UI thread. In this case it performs quite good. If the Sleep call is suppressed, the UI thread is basically stuck (as the background thread now calls the UI thread in a tight loop but don't sleep any more). In some cases, I even saw samples with some real processing keeping a Sleep call in the background thread (rather than trying to call back the UI thread less often) likely to solve this issue. That's why I wanted to draw attention on Sleeping not producing always the same effect than doing some actual work especially as the OP mentioned a "very long" sleep... Similarly, I assume that creating numerous sleeping threads could perhaps artificially lower the thread switching overhead. etc... So to avoid thinking about if a particular behavior could be altered by using Sleep rather than doing some actual work I prefer to always do actual work rather than using Sleep (even if this is just a tight loop that explicitely waits for a given elapsed time) in my threading test code... -- Patrice |