C# using AutoResetEvent
```class FooBar\n    {\n\t\t// initialized to true to indicate the first time there is no need to wait i.e. "foo" gets printed rightaway\n        private AutoRe
```class FooBar\n    {\n\t\t// initialized to true to indicate the first time there is no need to wait i.e. "foo" gets printed rightaway\n        private AutoResetEvent evt1 = new AutoResetEvent(true);\n\t\t\n\t\t// initialize to false to indicate that first time there is a need to wait i.e. "bar" won\'t get printed until told.\n        private AutoResetEvent evt2 = new AutoResetEvent(false);\n\n        private int n;\n\n        public FooBar(int n)\n        {\n            this.n = n;\n        }\n\n        public void Foo()\n        {\n            for (int i = 0; i < n; i++)\n            {\n                evt1.WaitOne();\n\n                Console.Write("foo");\n\n\t\t\t\t// Signal to the other guy that they are ok to proceed.\n                evt2.Set();\n            }\n        }\n\n        public void Bar()\n        {\n\n            for (int i = 0; i < n; i++)\n            {\n                evt2.WaitOne();\n\n                Console.Write("bar");\n\n\t\t\t\t// Signal to the other guy that they are ok to proceed.\n                evt1.Set();\n            }\n        }\n    }
[]