Not able to use inside Worker template
See original GitHub issue1. When running with RunTargetsAndExit
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
Target("default", () => System.Console.WriteLine("Hello, world!"));
RunTargetsAndExit(decimal);
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
await Task.Delay(1000, stoppingToken);
}
}
It runs first time but stops the application and gets stuck on
Waiting for the host to be disposed. Ensure all 'IHost' instances are wrapped in 'using' blocks.

2. When running with RunTargetsWithoutExiting
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
Target("default", () => System.Console.WriteLine("Hello, world!"));
RunTargetsWithoutExiting(default);
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
await Task.Delay(1000, stoppingToken);
}
}
It runs first time but gets stuck on

Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Worker Service - Missing Template · Issue #29940
After installing all prerequisites, the "Worker Service" template does still not appear in my list of project templates.
Read more >templates - Visual Studio 2022 Worker Service
I found this article useful: Where default templates are stored Note Visual Studio 2022 gets installed under Program Files (64 bit, not 86x) ......
Read more >Templates Not Showing in Create New Work Item
For my Azure DevOps project I am both an Administrator and Collaborator. In Team Configuration I have created templates for User Stories. I...
Read more >Worker Services - .NET
Learn how to implement a custom IHostedService and use existing implementations in C#. Discover various worker implementations, templates, ...
Read more >Worker Services in .NET Core 3.0 - The New Way ... - YouTube
In .NET Core 3.0, Microsoft has added a template called a Worker Service ... App template code overview 9:32 - Service App code...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@iAmBipinPaul the problem is that this line, when executed a second time, throws an exception:
This can be seen when setting VS to break when CLR exceptions are thrown:
I guess something in
Microsoft.Hosting.Extensionsis swallowing the exception.Anyway, I believe we’ve determined that Bullseye is behaving as expected, so on that basis I’m closing the issue.
Thanks @iAmBipinPaul, I’ll take a look ASAP.