public async static void RunWithTimeout() { var exchanger = new AsyncExchanger<string>(); var exchangerRetValues = new bool[NR_THREADS+1]; var exchangerExceptionValues = new bool[NR_THREADS+1]; var tasks = 0.To(NR_THREADS+1).Select(myId => TaskEx.Run<Task>( async () => { try { var exchangeId = await exchanger.Exchange(myId.ToString()).WithTimeout(1); exchangerRetValues[Int32.Parse(exchangeId)] = true; } catch (TimeoutException exception) { Console.WriteLine("Timeout"); exchangerExceptionValues[myId] = true; } }).Unwrap()).ToArray(); Task.WaitAll(tasks); Console.WriteLine("Ended With Timeout"); CheckWithException(exchangerRetValues, exchangerExceptionValues); }
public static void Run() { var exchanger = new AsyncExchanger<string>(); var exchangerRetValues = new bool[NR_THREADS]; var tasks = 0.To(NR_THREADS).Select(myId => TaskEx.Run<Task>( async () => { var exchangeId = await exchanger.Exchange(myId.ToString()); exchangerRetValues[Int32.Parse(exchangeId)] = true; }).Unwrap()).ToArray(); Task.WaitAll(tasks); Console.WriteLine("ENDED"); Check(exchangerRetValues); }