Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace ConsoleApplication1
- {
- class Program
- {
- private static Exception _exceptions;
- private static int _result;
- static void Main(string[] args)
- {
- if (Enter())
- {
- Func<int> _func = () =>
- {
- return 5;
- };
- CancellationTokenSource cts = new CancellationTokenSource();
- cts.Cancel();
- Task.Run(_func, cts.Token)
- .ContinueWith((antecedent) =>
- {
- try
- {
- antecedent.Wait(cts.Token);
- Interlocked.Exchange(ref _result, antecedent.Result);
- }
- catch (AggregateException e)
- {
- Interlocked.Exchange(ref _exceptions, e);
- }
- catch (OperationCanceledException)
- {
- ResetState();
- }
- catch (Exception e)
- {
- Interlocked.Exchange(ref _exceptions, new AggregateException(e));
- }
- finally
- {
- Exit();
- }
- });
- }
- }
- private static void Exit()
- {
- Console.WriteLine("Hit finally");
- }
- private static void ResetState()
- {
- return;
- }
- private static bool Enter()
- {
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement