如何在.NET 5中重新启动我的应用程序?
我有一个背景工人检查某些变量的状态,如果此变量与5分钟前相同,则意味着应用程序被冻结并且应该重新启动,这就是我实现此逻辑的方式,但这并不重新启动应用程序只是一个例外:
public void ExecuteAsync(CancellationToken stoppingToken)
{
Task.Run(async () =>
{
while (!stoppingToken.IsCancellationRequested)
{
await Task.Delay(TimeSpan.FromSeconds(_delayBetweenChecksInSeconds));
double exTotal = metricExTotal;
if (exTotal == _previousexTotal)
{
Environment.Exit(-1);
}
_previousexTotal = exTotal;
}
})
.ContinueWith(task =>
{
Environment.Exit(-1);
}, TaskContinuationOptions.OnlyOnFaulted)
.ConfigureAwait(false);
}
如何正确实现它,因此它将重新启动应用程序?
I have a background worker that checks state of some variable and if this variable the same as was 5 minutes ago, it means that application is frozen and should be restarted, that's is the way how I implemented this logic, but this don't restart app it just throw an exception:
public void ExecuteAsync(CancellationToken stoppingToken)
{
Task.Run(async () =>
{
while (!stoppingToken.IsCancellationRequested)
{
await Task.Delay(TimeSpan.FromSeconds(_delayBetweenChecksInSeconds));
double exTotal = metricExTotal;
if (exTotal == _previousexTotal)
{
Environment.Exit(-1);
}
_previousexTotal = exTotal;
}
})
.ContinueWith(task =>
{
Environment.Exit(-1);
}, TaskContinuationOptions.OnlyOnFaulted)
.ConfigureAwait(false);
}
How it could be correctly implemented, so it will restart app?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论