所以我有一个 dotnet 核心工作进程,我想在某些情况下关闭工作进程。
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
_logger.LogInformation("This is a worker process");
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
if (condition == true)
//do something to basically shutdown the worker process with failure code.
await Task.Delay(2000, stoppingToken);
}
}
我怎样才能做到这一点?我试图打破循环,但这并没有真正关闭工作进程。
//----this does not work-----
//even after doing this, Ctrl-C has to be done to shutdown the worker.
if (condition == true) break;