I have a .net 5.0 console application. I scheduled that application exe in task scheduler. Sometimes, when I end the task, the application kills without finishing the parts I have coded to finish. (I am stopping some services, and writing things in a file if the application exiting. It needs a little bit of time.)
I tried the following command but not working. It is doing the same things.
taskkill /t /f /im "ApplicationEXEName.exe"
I am looking for a way to do wait to finish my actions if application exiting.
I had tried setting ShutdownTimeout when the application host creating like this. But it also not working.
var host = Host.CreateDefaultBuilder()
.ConfigureAppConfiguration(ConfigConfiguration)
.ConfigureServices((context, services) =>
{
services.Configure<HostOptions>(opts => opts.ShutdownTimeout = TimeSpan.FromSeconds(15));
ConfigureDefaultServices(services);
ConfigureServices(configuration, services);
})
.UseSerilog(Log.Logger, true)
.Build();