George George

George George

  • NA
  • 778
  • 0

how to use event to re-write this code segment?

Jun 1 2008 9:13 PM

Hello everyone,


Here is my code segment for a thread, which will sleep one second, do some work and check if the stop status is set -- if set, then break the loop and stops the method.

My question is, whether it is possible to use event (e.g. ManualResetEvent) to implement similar logics?

[Code]
        void ThreadMethod1()
        {
            while (true)
            {
                Thread.Sleep(1000);
                if (stop)
                {
                    // break;
                }
                else
                {
                    // do something
                }
            }
        }
[/Code]


thanks in advance,
George


Answers (2)