コード例 #1
0
        public static void PreCanceledToken_ForAll()
        {
            OperationCanceledException caughtException = null;
            var cs = new CancellationTokenSource();

            cs.Cancel();

            IEnumerable <int> throwOnFirstEnumerable = Enumerables <int> .ThrowOnEnumeration();

            try
            {
                throwOnFirstEnumerable
                .AsParallel()
                .WithCancellation(cs.Token)
                .ForAll((x) => { Debug.WriteLine(x.ToString()); });
            }
            catch (OperationCanceledException ex)
            {
                caughtException = ex;
            }

            Assert.NotNull(caughtException);
            Assert.Equal(cs.Token, caughtException.CancellationToken);
        }
コード例 #2
0
 // Return an enumerable which throws on first MoveNext.
 // Useful for testing promptness of cancellation.
 public static IEnumerable <object[]> ThrowOnFirstEnumeration()
 {
     yield return(new object[] { Labeled.Label("ThrowOnFirstEnumeration", Enumerables <int> .ThrowOnEnumeration().AsParallel()), 8 });
 }
コード例 #3
0
ファイル: AssertThrows.cs プロジェクト: rsumner31/corefx2
        public static void AlreadyCanceled(Action <ParallelQuery <int> > query)
        {
            ParallelQuery <int> s = Enumerables <int> .ThrowOnEnumeration(new ShouldNotBeInvokedException(), 2).AsParallel().WithCancellation(new CancellationToken(canceled: true));

            OperationCanceledException oce = Assert.Throws <OperationCanceledException>(() => query(s));
        }