+ -
当前位置:首页 → 问答吧 → 关于BeginExecuteNonQuery异步操作我有两点疑问:

关于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);

作者: tianshi777   发布时间: 2011-03-14

CSDN 无人回复怎么发分

作者: tianshi777   发布时间: 2011-08-15

我会给你结贴

作者: zxxwlj   发布时间: 2011-08-15

我回复给你结贴

作者: zxxwlj   发布时间: 2011-08-15

热门下载

更多