Hi,
In C# in .NET Core Web App, I want to trigger a method to execute after a specific amount of time (seconds / minutes).
I need to "schedule" a large number of such methods executions (500-1000).
For example, below:
DoProcess(1) should execute in 1 seconds, DoProcess(2) in 2 seconds, DoProcess(3) in 3 seconds , etc...
DoProcess(2) should NOT to wait for DoProcess(1) to finish.
public async Task ProcessUsers()
{
for (var delay = 1; delay < 500; delay++)
{
Task.Delay(delay).ContinueWith(async task =>await DoProcess(delay));
}
}
public async Task DoProcess(int val)
{
}
1. Will that code work as I described?
2. Will each Task.Delay() create a new thread and (due to the large number of executions, 500) cause thread pool overload/exhaustion?
3. Can you suggest a better way to handle such requirement? I considered using some library like Quartz or Hangfire, but that seemed like an overkill.
What I have tried:
I provided above the code i wrote.