Procházet zdrojové kódy

修复DBQueryTask DBQueryBatchTask中的阻塞调用

tanghai před 7 roky
rodič
revize
509f22be23

+ 2 - 1
Server/Model/Module/DB/DBQueryBatchTask.cs

@@ -39,7 +39,8 @@ namespace ETModel
 					ComponentWithId component = dbCacheComponent.GetFromCache(this.CollectionName, id);
 					if (component == null)
 					{
-						component = await dbComponent.GetCollection(this.CollectionName).FindAsync((s) => s.Id == id).Result.FirstOrDefaultAsync();
+						IAsyncCursor<ComponentWithId> cursor = await dbComponent.GetCollection(this.CollectionName).FindAsync((s) => s.Id == id);
+						component = await cursor.FirstOrDefaultAsync();
 					}
 					
 					if (component == null)

+ 2 - 1
Server/Model/Module/DB/DBQueryTask.cs

@@ -34,7 +34,8 @@ namespace ETModel
 			try
 			{
 				// 执行查询数据库任务
-				component = await dbComponent.GetCollection(this.CollectionName).FindAsync((s) => s.Id == this.Id).Result.FirstOrDefaultAsync();
+				IAsyncCursor<ComponentWithId> cursor = await dbComponent.GetCollection(this.CollectionName).FindAsync((s) => s.Id == this.Id);
+				component = await cursor.FirstOrDefaultAsync();
 				this.Tcs.SetResult(component);
 			}
 			catch (Exception e)