Guest User

Untitled

a guest
Jan 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  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:
Add Comment
Please, Sign In to add comment