Quote:
Originally Posted by ercastro
Thank you for responding. I have actually used BackgroundWorker() already. My problem is how to wake up the BackgroundWorker() thread from Thread.Sleep using an Interrupt (ThreadInterruptException).
-- ercastro
Let me clarify what I need. I am using BackgroundWorker() to run a time-consuming task. I put the BackgroundWorker thread to sleep indefinitely by Thread.Sleep(Timeout.Infinite). I require 2 ways to wake the sleeping thread, whichever happens FIRST:
(1) Issue a Thread.Interrupt in the main thread when I detect a particular string in my text box (data from serial port), and catch this interrupt in BackgroundWorker as ThreadInterruptedException;
(2) As a backup, put a maximum time delay in case the desired string does not come up so that the BackgroundWorker thread will not sleep infinitely
I have already implemented step (1) after some research and experimentations. Now, my problem lies with step (2). I tried using the Timer control to fire up after the maximum time delay and issue a Thread.Interrupt, but the this never happens and BackgroundWorker sleeps forever. The Timer is enabled. I issue Timer.Start before issuing Thread.Sleep(Timeout.Infinite) at BackgroundWorker.
Thank you very much in advance.
-- ercastro