private static void MultiThreadedCancel(string constr, bool async) { using (SqlConnection con = new SqlConnection(constr)) { con.Open(); var command = con.CreateCommand(); command.CommandText = "select * from orders; waitfor delay '00:00:08'; select * from customers"; Thread rThread1 = new Thread(ExecuteCommandCancelExpected); Thread rThread2 = new Thread(CancelSharedCommand); Barrier threadsReady = new Barrier(2); object state = new Tuple <bool, SqlCommand, Barrier>(async, command, threadsReady); rThread1.Start(state); rThread2.Start(state); rThread1.Join(); rThread2.Join(); CommandCancelTest.VerifyConnection(command); } }
private static void MultiThreadedCancel(string constr, bool async) { using (SqlConnection con = new SqlConnection(constr)) { con.Open(); var command = con.CreateCommand(); command.CommandText = "select * from orders; waitfor delay '00:00:08'; select * from customers"; Barrier threadsReady = new Barrier(2); object state = new Tuple <bool, SqlCommand, Barrier>(async, command, threadsReady); Task[] tasks = new Task[2]; tasks[0] = new Task(ExecuteCommandCancelExpected, state); tasks[1] = new Task(CancelSharedCommand, state); tasks[0].Start(); tasks[1].Start(); Task.WaitAll(tasks, 15 * 1000); CommandCancelTest.VerifyConnection(command); } }