Beispiel #1
0
 /// <summary>
 /// 异步查询
 /// </summary>
 /// <param name="str"></param>
 /// <returns></returns>
 public static void QueryAsync(object obj)
 {
     string str = obj.ToString();
     AsyncQuery asyncQuery = new AsyncQuery(WordBLL.Query);
     IAsyncResult ar = asyncQuery.BeginInvoke(str, null, null);
     //在指定时间内不能重数据库或网页中提取出单词信息,则认为查询失败
     //int timeLimit = 5000;
     //if (ar.AsyncWaitHandle.WaitOne(timeLimit,false) == false)
     //{
     //    QueryResult.IsFinish = true;
     //    QueryResult.Result = new Word();
     //    QueryResult.Result.WordContent = QueryResult.FailInfo;
     //    return;
     //}
     QueryResult.Result = asyncQuery.EndInvoke(ar);
     if (ar.IsCompleted)
     {
         QueryResult.IsFinish = true;
         if (string.IsNullOrEmpty(QueryResult.Result.WordContent))
         {
             QueryResult.Result.WordContent = QueryResult.FailInfo;
         }
     }
 }