I am writing a windows service which creates a couple of parallels tasks to run: Following is the sample code snippet:
private static void TaskMethod1()
{
//I am doing a bunch of operations here, all of them can be replaced with a sleep for 25 minutes
}
private static async Task TaskMethod()
{
while(runningService)
{
// Thi will create more than one task in parallel to run and each task can take upto 30 minutes to finish
Task.Run(() => TaskMethod1(arg1);
}
}
internal static void Start()
{
runningService = true;
Task1 = Task.Run(() => TaskMethod());
}
internal static void Stop()
{
runningService = false;
Task1.Wait();
}
Now when I stop the service, it will not create any new tasks because runningService = false
but windows service doesn't wait for 30 minutes for already running tasks to get finished.
Now I read that there is an x minutes timeout for service and it can be changed using registry settings, I was just wondering if there is the way such that the service will wait for each task to be finished instead of hardcoding that time via the registry.