It looks like I’ve found a solution. Task.Run only queues the given work on the thread pool — it doesn’t start a new thread. So when I do something like this:
private async Task ReadFromHddAsync(string path)
{
await Task.Factory.StartNew(() =>
{
ReadFromHdd(path);
}, TaskCreationOptions.LongRunning);
}
private async Task SaveToHddAsync(string path)
{
await Task.Factory.StartNew(() =>
{
SaveToHdd(path);
}, TaskCreationOptions.LongRunning);
}
Then ManualResetEventSlim will not block another task.