问题描述
有没有办法运行 SqlCommand.ExecuteScalar()
异步,然后取消它(在服务器端也一样),而它正在执行?
Is there any way to run SqlCommand.ExecuteScalar()
asynchronously and then cancel it (on the server side as well) whilst it's being executed?
推荐答案
.NET框架4.5有一个ExecuteScalarAsync()方法。
在这里看到:http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalarasync(v=vs.110).aspx
.NET Framework 4.5 has a ExecuteScalarAsync() method.
See here: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalarasync(v=vs.110).aspx
ExecuteScalarAsync()也具有与可以在使用前的命令超时期满放弃的操作的参数的CancellationToken过载
ExecuteScalarAsync() also has an overload with a CancellationToken parameter that can be used to abandon the operation before the command timeout elapses.
这篇关于SqlCommand.ExecuteScalar取消的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!