Multithreading 资源组项目错误
尝试从以下位置使用此代码时: 我为我的初始调用创建了此方法:Multithreading 资源组项目错误,multithreading,asp.net-web-api,azure-logic-apps,Multithreading,Asp.net Web Api,Azure Logic Apps,尝试从以下位置使用此代码时: 我为我的初始调用创建了此方法: public async Task<dynamic> InsertRecords943(string interchangeId, [FromBody] dynamic inputjson) { Guid id = Guid.NewGuid(); RunningTasks[id] = string.Empty; new Thread(() => DoIn
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;
}
或将新螺纹线更改为:
await Task.Run(DoInsertRecords943(id, interchangeId, inputjson));
后者会工作吗?它不会仍然导致调用方超时吗?使其同步实际上应该是可行的。是的,好的捕获-您可能希望使方法同步-因为等待将使操作同步执行我们不希望的“长时间运行步骤” 希望这是有意义的-如果它能工作,LMK和我将修复我的代码:)
await Task.Run(DoInsertRecords943(id, interchangeId, inputjson));