Peter Osucha <[EMAIL PROTECTED]> wrote:

> As a test example, I have an IO line that I want to 'blink' (turn on and
> off for 250ms each).  I figured I could easily do this with a separate
> thread. 

> a while loop that continuously blinks the IO line using
> Sleep() statements - and one other property 'Stop' that can be set to
> 'true' to get out of the loop.  OK so far.

> If I didn't want to set the 'IsBackgroud' property of the thread, I
> figured I could just implement IDisposable in my class and set
> Blinker.Stop=true in Dispose().  However, that didn't seem to work.

That's because your thread isn't waiting for Blinker to finish. You
could call .Join on the thread object (and live with a delay of up to
250ms), or alternatively, instead of using Thread.Sleep, use a
ManualResetEvent. Signal the event for shutdown, and use the WaitOne
with a 250ms timeout for your blinking pause. The return value of
WaitOne will tell you whether the event was signalled or not; the thread
should quit when WaitOne returns true.

You should still call .Join on the thread, if you want to guarantee that
the thread has finished before the application shuts down.

-- Barry

-- 
http://barrkel.blogspot.com/

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to