我是Azure Webjobs的新手。我試圖實現GraceFul關機。同時使用WebJobsShutdownWatcher類。C在Azure Webjob中的GraceFul ShutDown#
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 ShutDown,我已停止Webjob並再次託管在天藍色。 在Azure上託管之後,隊列未獲得觸發器。當我調試代碼時,控制停止在WebJobsShutdownWatcher類。 我做了什麼錯了?
您應該刪除您Task.Run等待()()否則代碼後從不打。 – Thomas
你也可以看到這些帖子:https://stackoverflow.com/questions/35166010/azure-triggered-webjob-detecting-when-webjob-stops/ https://stackoverflow.com/questions/36760241/intercept-azure- function-host-shutdown-flush-application-insights-telemetryclie – Thomas