【发布时间】:2017-09-11 13:36:09
【问题描述】:
我是 Azure Webjobs 的新手。我试图实现 GraceFul 关机。在使用 WebJobsShutdownWatcher 类时。
Public static void Main()
{
try
{
var config = new JobHostConfiguration();
if (config.IsDevelopment)
{
config.UseDevelopmentSettings();
}
var watcher = new WebJobsShutdownWatcher();
Task.Run(() =>
{
bool isCancelled = false;
while (!isCancelled)
{
if (watcher.Token.IsCancellationRequested)
{
Console.WriteLine("WebJob cancellation Token Requested!");
isCancelled = true;
}
}
}, watcher.Token).Wait();
var host = new JobHost();
The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
catch (Exception)
{
Console.WriteLine("Error");
}
}
为了实现 GraceFul 关闭,我已停止 Webjob 并再次托管在 azure 上。 在 Azure 上托管后,队列没有触发。当我调试代码时,控件在 WebJobsShutdownWatcher 类处停止。 我做错了什么?
【问题讨论】:
-
你应该删除 Task.Run() 上的 Wait() 否则后面的代码永远不会被命中。
标签: c# azure queue azure-webjobs