2
Answers

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

George George

George George

16y
2k
1

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)