daily pastebin goal
0%
SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Tokens for cancellation
  2.             ParallelOptions po = new ParallelOptions();
  3.             po.CancellationToken = cts.Token;
  4.  
  5.             try
  6.             {
  7.                 Parallel.ForEach(queries, po, (currentQuery) =>
  8.                 {
  9.                     // Execute query
  10.                     ExecuteQuery(currentQuery);
  11.  
  12.                     // Throw exception if cancelled
  13.                     po.CancellationToken.ThrowIfCancellationRequested(); // ***
  14.                 });
  15.             }
  16.             catch (OperationCanceledException cancelException)
  17.             {
  18.                 Console.WriteLine(cancelException.Message);
  19.             }
  20.    
  21. System.OperationCanceledException was unhandled by user code
  22.   Message=The operation was canceled.
  23.   Source=mscorlib
  24.   StackTrace:
  25.    at System.Threading.CancellationToken.ThrowIfCancellationRequested()
  26.    at CraigslistReader.SearchObject.<>c__DisplayClass7.<bw_DoWork>b__5(Query currentQuery) in {PATH}:line 286
  27.    at System.Threading.Tasks.Parallel.<>c__DisplayClass2d`2.<ForEachWorker>b__23(Int32 i)
  28.    at System.Threading.Tasks.Parallel.<>c__DisplayClassf`1.<ForWorker>b__c()
  29. InnerException:
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top