© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
143 replies
Kasumi

Windows Worker Service times out

Hello. Everytime I want to start my Worker Service I get the message that it doesnt reacted in time and I dont know why I get this error. because everytime I run the exe noremally the whole thing works.

Program.cs

using My_Service;

HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);
builder.Services.AddHostedService<Worker>();
IHost host = builder.Build();
await host.RunAsync();
using My_Service;

HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);
builder.Services.AddHostedService<Worker>();
IHost host = builder.Build();
await host.RunAsync();

Worker.cs
using System.Net.Mime;

namespace My_Service;


public class Worker : BackgroundService
{
    private readonly ILogger<Worker> _logger;

    public Worker(ILogger<Worker> logger)
    {
        _logger = logger;
    }
    
    
    
    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    {
        
        while (!stoppingToken.IsCancellationRequested)
        {
            _logger.LogInformation("My Service running at: {time}", DateTimeOffset.Now);
            try
            {
                myServiceCode.systemcode();
                _logger.LogInformation("Started Service Service Code");
                //await Task.Delay(1_000, stoppingToken);
            }
            catch (Exception e)
            {
                _logger.LogError("Error in Service Code: {e}", e);
            }
            await Task.Delay(60000, stoppingToken);
        }
    }
}
using System.Net.Mime;

namespace My_Service;


public class Worker : BackgroundService
{
    private readonly ILogger<Worker> _logger;

    public Worker(ILogger<Worker> logger)
    {
        _logger = logger;
    }
    
    
    
    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    {
        
        while (!stoppingToken.IsCancellationRequested)
        {
            _logger.LogInformation("My Service running at: {time}", DateTimeOffset.Now);
            try
            {
                myServiceCode.systemcode();
                _logger.LogInformation("Started Service Service Code");
                //await Task.Delay(1_000, stoppingToken);
            }
            catch (Exception e)
            {
                _logger.LogError("Error in Service Code: {e}", e);
            }
            await Task.Delay(60000, stoppingToken);
        }
    }
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

Worker Service AzureClients
C#CC# / help
15mo ago
gRPC Windows Service
C#CC# / help
4mo ago
✅ Hosted Service running as Windows Service
C#CC# / help
2y ago