Jeremy Boyd
Jeremy Boyd

Reputation: 5403

How to break Parallel.ForEach on Timeout

How do you break the execution of a Parallel.ForEach() loop at a timeout interval?

I have tried the CancelizationTokenSource but that cancels the entire ForEach. I just want the one task to cancel, not the entire loop.

Upvotes: 1

Views: 2124

Answers (1)

KeithS
KeithS

Reputation: 71573

You'd have to set up the task to be performed by Parallel.ForEach with its own timeout mechanism, which would end the task thread without performing the operation, but also without telling Parallel.ForEach that there's a problem big enough for it to terminate the entire operation.

Upvotes: 3

Related Questions