[C#] blocking threads with AutoResetEvent primitives
Intuition\nFirst thing that came to my mind was to block second, then third method until prefious will be completed\n\n# Approach\nI decided to block set blocke
# Intuition\nFirst thing that came to my mind was to block second, then third method until prefious will be completed\n\n# Approach\nI decided to block set blockers in second and third methods. We create 2 blockers in nonsignal state, that means the method WaitOne() will block threads. \n\nMethod First() without blockers, after running printFirst() we transfer _secondBlocker in signal state by running method Set(), so _secondBlocker unblocks blocked threads. The same with method Third()\n\n# Code\n```\nusing System.Threading;\n\npublic class Foo {\n    private readonly AutoResetEvent _secondBlocker = new AutoResetEvent(false);\n    private readonly AutoResetEvent _thirdBlocker = new AutoResetEvent(false);\n\n    public Foo() {\n        \n    }\n\n    public void First(Action printFirst) {\n        printFirst();\n        _secondBlocker.Set();\n    }\n\n    public void Second(Action printSecond) {\n        _secondBlocker.WaitOne();\n        printSecond();\n        _thirdBlocker.Set();\n    }\n\n    public void Third(Action printThird) {\n        _thirdBlocker.WaitOne();\n        printThird();\n    }\n}\n```
['C#']