0
當試圖從使用此代碼: LogicAppsAsyncResponseSample 我創造了這個方法,我最初的呼叫:資源組項目錯誤
public async Task<dynamic> InsertRecords943(string interchangeId, [FromBody] dynamic inputjson)
{
Guid id = Guid.NewGuid();
RunningTasks[id] = string.Empty;
new Thread(() => DoInsertRecords943(id, interchangeId, inputjson)).Start(); //Start the thread of work, but continue on before it completes
HttpResponseMessage responseMessage = Request.CreateResponse(HttpStatusCode.Accepted);
responseMessage.Headers.Add("location", String.Format("{0}://{1}/api/status/{2}", Request.RequestUri.Scheme, Request.RequestUri.Host, id));
responseMessage.Headers.Add("retry-after", "20");
return responseMessage;
}
但代碼分析是生產這個錯誤:
錯誤CS1998這種異步方法缺少'等待'操作符並且會同步運行。考慮使用'await'操作符來等待非阻塞API調用,或者'等待Task.Run(...)'在後臺線程上執行CPU綁定工作。
我也是想使方法同步:
public dynamic InsertRecords940(string interchangeId, [FromBody] dynamic inputjson)
或更換新的主題線路是:
await Task.Run(DoInsertRecords943(id, interchangeId, inputjson));
請問後來連工作,會不會仍然導致來電者超時?使其同步應該實際上工作。