/// <summary> /// Schedules action to be executed. /// </summary> public IDisposable Schedule(Action action) { if (action == null) throw new ArgumentNullException("action"); var cancelable = new CancellationDisposable(); taskFactory.StartNew(() => { try { action(); } catch (Exception ex) { var raise = new Thread(() => { throw ex.PrepareForRethrow(); }); raise.Start(); raise.Join(); } }, cancelable.Token); return cancelable; }
public void CancellationDisposable_TokenCtor() { var t = new CancellationTokenSource(); var c = new CancellationDisposable(t); Assert.IsTrue(t.Token == c.Token); Assert.IsFalse(c.Token.IsCancellationRequested); Assert.IsTrue(c.Token.CanBeCanceled); c.Dispose(); Assert.IsTrue(c.Token.IsCancellationRequested); }
public void CancellationDisposable_DefaultCtor() { var c = new CancellationDisposable(); Assert.IsNotNull(c.Token); Assert.IsFalse(c.Token.IsCancellationRequested); Assert.IsTrue(c.Token.CanBeCanceled); c.Dispose(); Assert.IsTrue(c.Token.IsCancellationRequested); }