להדפיס לפי סדר
אותו מופע של מחלקה תועבר ל 3 threads. בכל מקרה צריך להדפיס first,second, third לפי סדר.
- public class Foo {
- private readonly System.Threading.EventWaitHandle waitHandle1 = new System.Threading.AutoResetEvent(false);
- private readonly System.Threading.EventWaitHandle waitHandle2 = new System.Threading.AutoResetEvent(false);
- public void First(Action printFirst) {
- printFirst();
- waitHandle1.Set();
- }
- public void Second(Action printSecond) {
- waitHandle1.WaitOne();
- printSecond();
- waitHandle2.Set();
- waitHandle1.Reset();
- }
- public void Third(Action printThird) {
- waitHandle2.WaitOne();
- printThird();
- waitHandle2.Reset();
- }
- }