【发布时间】:2019-02-18 00:16:48
【问题描述】:
我正在使用 webclient 代码执行操作结果 LongRunningProcess,无论如何要在外部停止进程执行而不是在 iis 中停止它?
public IHttpActionResult LongRunningProcess()
{
for (int i = 0; i < 5000000; i++)
{
Thread.Sleep(1000);
}
return Json("Completed");
}
using (WebClient wc = new WebClient())
{
string myParameters = "";
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
string HtmlResult =await wc.UploadStringTaskAsync("http://...../LongRunningProcess", myParameters);
}
【问题讨论】:
-
如果您不将进程移交给 IIS 外部(例如转到 MSMQ),那么您将不得不对线程进行一些魔术。
-
这可能会让您了解使用线程所需的工作量:docs.microsoft.com/en-us/dotnet/standard/threading/…
-
检查cancellationToken是否适合您的场景。更多信息:stackoverflow.com/questions/19010856/…
标签: asp.net-mvc asp.net-mvc-4 asp.net-web-api asp.net-web-api2