我想知道是否可以改进此代码以获得更好的性能。我对服务器端的整个异步操作很陌生,所以请在这里耐心等待:
con.GetGame(id, game => {
foreach(Player p in game.Team1)
{
p.SomeExtraDetails = GetPlayerDetails(p.Id);
}
// I would like the player data to be set on all players
// before ending up here
});
private PlayerDetails GetPlayerDetails(double playerId)
{
var task = con.GetPlayer(playerId);
PlayerDetails ret = null;
Task continuation = task.ContinueWith(t =>
{
ret = t.Result;
});
continuation.Wait();
return ret;
}
如果我做对了,就continuation.Wait();
阻塞主线程。
有没有办法让任务同时运行?