Untitled
unknown
plain_text
2 years ago
845 B
5
Indexable
using System; using System.Threading; class Program { static void Main(string[] args) { int n = 10; AutoResetEvent t1Event = new AutoResetEvent(false); AutoResetEvent t2Event = new AutoResetEvent(false); Thread t1 = new Thread(() => { for (int i = 1; i <= n; i += 2) { Console.WriteLine("Thread 1: " + i); t2Event.Set(); t1Event.WaitOne(); } }); Thread t2 = new Thread(() => { for (int i = 2; i <= n; i += 2) { t2Event.WaitOne(); Console.WriteLine("Thread 2: " + i); t1Event.Set(); } }); t1.Start(); t2.Start(); Console.ReadKey(); } }
Editor is loading...