Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timer doesn't start on start of service. #1103

Open
ShelestSergey opened this issue Dec 8, 2024 · 4 comments
Open

Timer doesn't start on start of service. #1103

ShelestSergey opened this issue Dec 8, 2024 · 4 comments

Comments

@ShelestSergey
Copy link

I have service using SoapCore.
There's some transient SoapEndpoints
builder.Services.AddTransient<ICarService, CarService>(); app.UseSoapEndpoint<ICarService>("/dict/Car.asmx", new SoapEncoderOptions());

and Timer. as HostedService
builder.Services.AddSingleton<BatchTimerService>(); builder.Services.AddHostedService(sp => sp.GetRequiredService<BatchTimerService>());
And I have strange situation when Timer doesn't start until one of methods is called.
I don't know, but maybe it's normal situation. Because it's my first SOAP project.

@ShelestSergey
Copy link
Author

Forgot to say, that this issue is only when I start service via IIS.
When I start exe manually, everything's fine.

@ShelestSergey
Copy link
Author

    public Task StartAsync(CancellationToken stoppingToken)
    {
        _logger.LogInformation("{Service} started.", nameof(RefAssignmentTimerService));

        _version = settings.Value.Version.Assignment;
        _timer = new Timer(async state => await DoWork(), null, TimeSpan.Zero, TimeSpan.FromSeconds(_settings.Value.TimerTimeOut.Assignment));
        return _completedTask;
    }

@andersjonsson
Copy link
Collaborator

By default, IIS starts the application pool on demand and then shuts it down after a while if there are no requests.
I think what you're looking for is to set the application pool to "AlwaysRunning"

@ShelestSergey
Copy link
Author

@andersjonsson thank you,
But It doesn't work. But I think you right and I have to dig into IIS properties.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@andersjonsson @ShelestSergey and others