【发布时间】:2018-12-14 20:27:39
【问题描述】:
我希望我的申请能够优雅地结束。有可能这样做吗?如果是这样,我将如何做到这一点?
以下是应用程序外观的一般概述:
// .NET Core Console App
while (true)
{
// Get the next message from the Queue. The Queue is a database table that contains a list of "things that need to be done".
// Spawn a Task to handle that message. Send the Task all the data it requires to complete. Generally speaking, the Task will collate all the data in an object and make a call (PUT, POST, DELETE) against a set of RESTful web services.
// Sleep for some time.
Thread.Sleep(sleepTimeInSeconds * 1000);
}
此应用程序通常会在某些服务器上不间断地运行。但是,如果用户需要将其关闭,我希望该作业能够优雅地退出:
- 停止查询队列以获取更多消息。查询到的消息被数据库锁定,其他进程无法处理同一条消息。
- 允许完成所有正在运行的任务。
有可能做到这一点吗?我可以使用哪些技术/库/概念来实现这一目标?
【问题讨论】: