从未来的更新:TL; DR赶上你要异步方法表达await
, Task.WaitAll
,或.Result
。
我创造了只运行其他异步方法有点令人费解的异步方法。 您可以忽略大部分仅行VAR mSpekTask ...感兴趣,另外,我不在乎逻辑,我只是想知道我的异常去。 我的主要问题是,ex.ToString()是从来没有击中即使内部mSpecTask异常definitly发生。
public async Task LoadAsync(IEnumerable<ProductRequest> feed, int? customerId,
IProgress<int> mSpecProgress, Action<Task> mSpecCompletionHandler)
{
var ids = feed.Select(x => x.ProductId.ToString()).Distinct().ToList();
try
{
var mSpecTask = this.LoadMSpecAsync(mSpecProgress, ids);
}
catch (Exception ex)
{
ex.ToString();
}
}
下面是LoadMSpecAsync代码
public Task<ResultSet> LoadMSpecAsync(IProgress<int> prg,
IEnumerable<string> ids)
{
return this.LoadAsync(prg, ids, Selector.M, SPMS, x => x.Order);
}
下面是LoadAsync代码,等待db.ExecuteTVP(进展,spName,IDS,参数)生成异常。
private async Task<Dictionary<Pair, dynamic>> LoadAsync(IProgress<int> progress,
IEnumerable<string> ids, Selector s, string spName, Func<dynamic, int> k,
Func<dynamic, dynamic> f = null, object parameters = null)
{
parameters = new ExpandoObject().CopyFromSafe(parameters);
if (spName != SPMAP) ((dynamic)parameters).lang = this.languageCode;
using (var db = new SqlConnection(this.connectionString))
{
await db.OpenAsync();
var results = await db.ExecuteTVP(progress, spName, ids, parameters);
db.Close();
}
return this.data[s];
}