Advertisement
Guest User

Untitled

a guest
Jun 20th, 2013
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.53 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3. using System.Threading.Tasks;
  4.  
  5.  
  6. public class Test {
  7.     static void Main() {
  8.         var cts = new CancellationTokenSource();
  9.         var ct = cts.Token;
  10.         var task = Task.Factory.StartNew(() => TaskAction(ct), ct);
  11.         task.ContinueWith(t => Console.WriteLine(t.Status));
  12.  
  13.         //cts.Cancel();
  14.  
  15.         Console.ReadKey();
  16.     }
  17.  
  18.     static void TaskAction(CancellationToken ct) {
  19.         Thread.Sleep(1000);
  20.         throw new OperationCanceledException(ct);
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement