Я запустил 1 процесс, используя стартовое действие, теперь мне нужно завершить этот процесс, когда я вызываю стоповое действие, как лучше всего его заархивировать?
Ниже мой код:
public class TestController : Controller
{
private static ManualResetEvent mre = new ManualResetEvent(false);
[HttpGet]
Route("api/Start")]
public async Task<JsonResult> Start()
{
ThreadPool.RegisterWaitForSingleObject(
mre,
// Method to execute
async (state, timeout) =>
{
// code wchich will run every 1 minute
},
// optional state object to pass to the method
null,
// Execute the method after 5 seconds
TimeSpan.FromSeconds(60),
// Set this to false to execute it repeatedly every 5 seconds
false
);
return Json("started");
}
[HttpGet]
[Route("api/Stop")]
public async Task<JsonResult> Stop()
{
// Need code to stop/kill Thread created in start action
return Json("stopped");
}
}