关于BeginExecuteNonQuery异步操作我有两点疑问:
时间:2011-03-14
来源:互联网
AsyncCallback callback = new AsyncCallback(QuanJuClass.HandleCallback);
command.BeginExecuteNonQuery(callback, command);
关于BeginExecuteNonQuery异步操作我有两点疑问:
1. 哪些情况会导致不调用(不执行)QuanJuClass.HandleCallback(IAsyncResult result) 这个方法?
2. 调用进QuanJuClass.HandleCallback(IAsyncResult result)后,什么情况会出现 result.IsCompleted 为false ?
3. 这个异步过程中,有没有超时处理?如果有怎么设置超时时间,超时了怎么处理
?
代码
回调函数
public static void HandleCallback(IAsyncResult result)
{
try
{
SqlCommand command = (SqlCommand)result.AsyncState;
if (result.IsCompleted)
{
int x = command.EndExecuteNonQuery(result);
WriteLog("command.EndExecuteNonQuery(result) 影响行数: " + x);
}
else
{
WriteLog("result.IsCompleted=false");
}
if (command.Connection != null && command.Connection.State != ConnectionState.Closed)
{
command.Connection.Close();
}
}
catch (Exception)
{
//this.Invoke(new DisplayStatusDelegate(DisplayStatus),
// "Error: " + ex.Message);
}
finally
{
//isExecuting = false;
}
}
调用
SqlCommand command = new SqlCommand(commandText, connection);
if (connection.State != ConnectionState.Open)
connection.Open();
AsyncCallback callback = new AsyncCallback(QuanJuClass.HandleCallback);
command.BeginExecuteNonQuery(callback, command);
command.BeginExecuteNonQuery(callback, command);
关于BeginExecuteNonQuery异步操作我有两点疑问:
1. 哪些情况会导致不调用(不执行)QuanJuClass.HandleCallback(IAsyncResult result) 这个方法?
2. 调用进QuanJuClass.HandleCallback(IAsyncResult result)后,什么情况会出现 result.IsCompleted 为false ?
3. 这个异步过程中,有没有超时处理?如果有怎么设置超时时间,超时了怎么处理
?
代码
回调函数
public static void HandleCallback(IAsyncResult result)
{
try
{
SqlCommand command = (SqlCommand)result.AsyncState;
if (result.IsCompleted)
{
int x = command.EndExecuteNonQuery(result);
WriteLog("command.EndExecuteNonQuery(result) 影响行数: " + x);
}
else
{
WriteLog("result.IsCompleted=false");
}
if (command.Connection != null && command.Connection.State != ConnectionState.Closed)
{
command.Connection.Close();
}
}
catch (Exception)
{
//this.Invoke(new DisplayStatusDelegate(DisplayStatus),
// "Error: " + ex.Message);
}
finally
{
//isExecuting = false;
}
}
调用
SqlCommand command = new SqlCommand(commandText, connection);
if (connection.State != ConnectionState.Open)
connection.Open();
AsyncCallback callback = new AsyncCallback(QuanJuClass.HandleCallback);
command.BeginExecuteNonQuery(callback, command);
作者: tianshi777 发布时间: 2011-03-14
CSDN 无人回复怎么发分
作者: tianshi777 发布时间: 2011-08-15
我会给你结贴

作者: zxxwlj 发布时间: 2011-08-15
我回复给你结贴

作者: zxxwlj 发布时间: 2011-08-15
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28