c# - Cancelling long-running tasks in PLINQ -


I am trying to use the .NET 4.0 parallel task library to manage multiple FTS queries. If the query takes a lot of time, I want to cancel it and want to proceed with the rest of the process.

When a query goes to the threshold, this code does not stop. I think I am saying that the canceled work and time limit have reached the whole process instead of a single transaction. If I set the time duration to be very small (300 mms), then it is called for all search strings.

I think that I do not have anything clear ... thanks in advance for any insights.

Additionally, executing it still does not seem to stop a long query. Is this also a perfect way to cancel a long-running query, which triggered it?

Revised code:

  CancelTokenSource CTS = new cancellation TokenSaur (); Cancellation token token = CTS. Token; Var query = searchString.Values.Select (c => myLongQuery (c)). AsParallel (). ASOrdered (). Quit (counter * numToProcess). Take (numToProcess). With control (cts.Token); New thread (() = & gt; {thread.Sleep (5000); cts.Cancel ();}). Start (); {List & lt; List & lt; Threads & gt; & Gt; Results = Query. Toolist (); Foreach (in threads> Threads & gt; threads in the list) {// does something with data}} Catch (OperationConnected Expression) {Console.WriteLine ("The query took too long"); PLINQ will select token to cancel after every few elements.  

If the frequency of checks for your application is inadequate, make sure that all expensive representatives in the PLINQ query call CTS regularly.Token Throws If Consequentialized (). For more information, see this article:


Comments