I was wondering what is the best way to fake a long-term task when several tasks are performed in parallel. The first thing that comes to mind is Thread.Sleep
public void FakeLongRunningTask()
{
Thread.Sleep(5000);
}
However, the problem with the above code is that calling Thread.Sleep blocks this thread, which means that it will refuse CPU time, so calling a method with Thread.Sleep in a parallel environment is as good as not calling it at all, therefore, if I run three tasks in parallel, and one of them calls Thread.Sleep, this task will not affect performance (although this may cause the CLR to generate more threads !!!). But I want to fake a task that will affect overall performance.
source
share