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,427
  • 2
  • 16
  • 26

1 Answers1

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,736
  • 7
  • 61
  • 88