这段代码,没有await
,编译:
IEnumerable<PingResponse> pingResponses;
using (var prestoWcf = new PrestoWcf<IPingService>())
{
pingResponses = prestoWcf.Service.GetAllForPingRequest(this.PingRequest);
}
foreach (PingResponse response in pingResponses) { // code here }
带有 的这段代码await
无法编译:
IEnumerable<PingResponse> pingResponses;
await Task.Factory.StartNew(() =>
{
using (var prestoWcf = new PrestoWcf<IPingService>())
{
pingResponses = prestoWcf.Service.GetAllForPingRequest(this.PingRequest);
}
});
foreach (PingResponse response in pingResponses) { // code here }
错误是:Use of unassigned local variable 'pingResponses'
为什么引入 async/await 会导致这个问题?