public void CommandCancellationTest() { if (GetServerVersion() < new Version("2.5.0.0")) { Assert.Inconclusive("Not supported on this version."); return; } bool cancelled = false; using (FbCommand cmd = Connection.CreateCommand()) { cmd.CommandText = @"execute block as declare variable start_time timestamp; begin start_time = cast('now' as timestamp); while (datediff(second from start_time to cast('now' as timestamp)) <= 10) do begin end end"; cmd.BeginExecuteNonQuery(o => { try { cmd.EndExecuteNonQuery(o as IAsyncResult); } catch (FbException ex) { cancelled = "HY008" == ex.SQLSTATE; } }, null); System.Threading.Thread.Sleep(2000); cmd.Cancel(); System.Threading.Thread.Sleep(2000); Assert.IsTrue(cancelled); } }
public void CommandCancellationTest() { if (!EnsureVersion(new Version("2.5.0.0"))) { return; } bool cancelled = false; using (FbCommand cmd = Connection.CreateCommand()) { cmd.CommandText = @"execute block as declare variable start_time timestamp; begin start_time = cast('now' as timestamp); while (datediff(second from start_time to cast('now' as timestamp)) <= 10) do begin end end"; ThreadPool.QueueUserWorkItem(_ => { try { cmd.ExecuteNonQuery(); } catch (FbException ex) { cancelled = "HY008" == ex.SQLSTATE; } }); Thread.Sleep(2000); cmd.Cancel(); Thread.Sleep(2000); Assert.IsTrue(cancelled); } }