In our .NET framework services, we always request additional time from the service control manager when our services start to give them more time to start than the default (30 seconds?) before reporting that they haven't started.
We do this using the RequestAdditionalTime method of the ServiceBase class, e.g.
protected override void OnStart(string[] args)
{
RequestAdditionalTime(120 * 1000);
// Do stuff.
}
We do this because we check some stuff like version compatibility with the SQL database runnning in SQL Server before starting any of the other threads etc in case the service should not start. What we found was that SQL Server was not always running in time for the service to connect to it at startup so we ask that the service control manager gives the service more time to start up so that we can retry database connection.
I want to do the same with our .NET core 3 services but can't find any equivalent way to request additional time from the service control manager. So if we have a BackgroundService that we've configured with UseWindowsService() in the host builder, how do I get to request more time like we do with .NET Framework?
public class Worker : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
CheckDatabaseCompatibility();
while (!stoppingToken.IsCancellationRequested)
{
// Do stuff.
}
}
}
We're using .NET Core 3.1.1 and running the exe as a service in Windows.