0

Is there a way in C# to wait until a specific task returns or timeout after a specified number of milliseconds, withOUT making all the other tasks running on the same thread be blocked as well ?

xander
  • 1,387
  • 2
  • 15
  • 25

2 Answers2

1

Assuming you are starting the tasks individually, and not using Parallel.For/ForEach/Invoke, etc. i.e. You are getting a Task object back, then something like this:

Task taskIWantToWaitFor = Task.Factory.Start(....);
// Other code
taskIWantToWaitFor.Wait(millisecondsTimeout)
// All other tasks continue in the background
Colin Mackay
  • 18,132
  • 6
  • 62
  • 84
-1

I reference the answer of @Dorus on this topic:

TL;DR:

Task delay = Task.Delay(5000);
await delay;
Tomerikoo
  • 15,737
  • 15
  • 35
  • 52
Nousie94
  • 14
  • 2