为什么为未使用的变量赋值会对此异步代码的function产生影响?
我有这个代码:
private async Task SavePlatypusComplianceFileOnServer(string year, string month) { string monthAsMM = ReportRunnerConstsAndUtils.GetMonthAsMM(month); HttpClient client = new HttpClient(); client.BaseAddress = new Uri(ReportRunnerConstsAndUtils.SERVER_BASE_ADDRESS); String uriToCall = String.Format("/api/PlatypusCompliance/{0}/{1}{2}", _unit, year, monthAsMM); HttpResponseMessage response = await client.PostAsync(uriToCall, null); }
……工作正常
不过,看着它,我心里想,“自我,为什么你在不使用它时为”响应“赋值?为什么不在没有它的情况下调用方法?毕竟,Visual Studio或Resharper灰色用“回应”表示你没有实际意义/冗余。“
所以我将代码更改为:
private async Task SavePlatypusComplianceFileOnServer(string year, string month) { . . . // all but the last line of the code is exactly the same await client.PostAsync(uriToCall, null); }
但是随着这种变化,所有达拉斯都会崩溃 – 我得到的错误消息是关于表不能被删除因为它们不存在,并且通过PostAsync()调用该方法不成功。
为什么在不使用时为响应分配值是否会产生差异?
- Azure Service Fabric Actors – 未处理的exception?
- 在自定义AuthorizeAttribute中访问QueryString
- 如何创建一个文件来填充HttpContext.Current.Request.Files?
- ModelBindervalidation使用reflection在getter上中断
- Unity IoC不会将dependency injectionWeb API Controller
- 将逻辑调用上下文从OWIN管道传递到WebApi控制器
- 使用APIController补充序列化
- 如何在HttpClient response.ReasonPhrase中获取真正的错误消息?
- 将对象序列化为已包含一个JSON属性的JSON