[Mono-list] Thread interrupt : Not implemented
jonpryor at vt.edu
Wed Nov 1 05:41:50 EST 2006
On Wed, 2006-11-01 at 10:58 +0100, xiii29 wrote:
> In my apps, I'm using a separate thread to collect data. When it has
> finished, I call the Sleep method.
I obviously don't know anything about your app, but this sounds
terrible. It sounds like your other thread is within a polling loop (do
work, sleep, do work, sleep...), which is generally bad as it's
inefficient. Worst case, if no work is available, your thread will
periodically wake up to check for the (nonexistent) work, then go back
to sleep. This will prevent the OS from paging your program out to
disk, eat up additional battery (due to increased CPU & disk use) on
laptop systems, slow other processes down, and more.
You should instead use ThreadHandle.WaitOne() on a ThreadHandle
subclass, like System.Threading.AutoResetEvent or
System.Threading.ManualResetEvent. The other thread can wake the
waiting thread with *ResetEvent.Set() or *ResetEvent.Reset().
Check the class documentation for more details.
More information about the Mono-list