2 years ago
#21483
AliK
.NET Core console app does not run all processes (sometimes)
Just wondering if anyone has experience this issue before. We run console apps as scheduled tasks using windows Task Scheduler and 99% of the time they run as expected but there are times where it seems the app does not run to the end and just stops before executing the next process.
I have given very simple code here for example of what we do so should give an idea about the issue. Don't be too concerned where the objects are coming from or how they are created as that is not the issue.
public class Program
{
static async Task Main()
{
Console.Write("A Task");
var watch = System.Diagnostics.Stopwatch.StartNew();
foreach (var customer in listOfCustomers)
{
_logger.LogInformation($"Processing {Customer}");
await ProcessCustomer(customer);
}
Console.Write("End of A Task");
}
private static async Task ProcessCustomer(Customer customer)
{
_logger.LogInformation($"Processing");
}
}
As mentioned most of the time all is ok. The issue is that sometimes we are seeing the following behaviou.
The log entry for 'Processing Customer' is shown but then it just stops without error/failure and the 'End of A Task' message is never logged nor is any message in ProcessCustomer.
Seems to be random so just wondering if anyone has experienced this.
c#
.net-core
windows-task-scheduler
0 Answers
Your Answer