C# AutoResetEvent
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nusing System.Threading;\npublic class FooBar {\n    private int n;\n\n    AutoResetEvent auto=new AutoResetEvent(false);\n    AutoResetEvent auto2=new AutoResetEvent(false);\n\n    public FooBar(int n) {\n        this.n = n;\n    }\n\n    public void Foo(Action printFoo) {\n        \n        for (int i = 0; i < n; i++) {\n            \n        \t// printFoo() outputs "foo". Do not change or remove this line.\n        \tprintFoo();\n            auto.Set();\n            auto2.WaitOne();\n        }\n    }\n\n    public void Bar(Action printBar) {\n        \n       \n        for (int i = 0; i < n; i++) {\n             auto.WaitOne();\n            // printBar() outputs "bar". Do not change or remove this line.\n        \tprintBar();\n            auto2.Set();\n        }\n    }\n}\n```
['C#']