当前位置: 首页>>代码示例>>C#>>正文


C# ConcurrentBag.All方法代码示例

本文整理汇总了C#中ConcurrentBag.All方法的典型用法代码示例。如果您正苦于以下问题:C# ConcurrentBag.All方法的具体用法?C# ConcurrentBag.All怎么用?C# ConcurrentBag.All使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ConcurrentBag的用法示例。


在下文中一共展示了ConcurrentBag.All方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Instance_ThreadSafe

        public void Instance_ThreadSafe()
        {

            using (var gate = new Barrier(5))
            {
                var result = new ConcurrentBag<AnyConstructorFinder>();

                Action test = () =>
                {
                    gate.SignalAndWait(20);

                    var instance = AnyConstructorFinder.Instance;

                    Thread.MemoryBarrier();

                    result.Add(instance);
                };

                var cycleState = Parallel.For(0, 200,
                    new ParallelOptions { MaxDegreeOfParallelism = 15 },
                    x => { test(); })
                    ;

                while (!cycleState.IsCompleted) 
                {
                    Thread.Sleep(100);
                }

                Assert.IsTrue(result.All(x => x != null));
                Assert.IsTrue(result.Distinct().Count() == 1);
            }
        }
开发者ID:pgatilov,项目名称:weather.nsu.ru.azure,代码行数:32,代码来源:AnyConstructorFinderTests.cs

示例2: AddressUidExtension_should_always_report_same_value

 public void AddressUidExtension_should_always_report_same_value()
 {
     var values = new ConcurrentBag<int>();
     var parallelOps = 1000;
     var loop = Parallel.For(0, parallelOps, i =>
     {
         values.Add(AddressUidExtension.Uid(Sys));
     });
     SpinWait.SpinUntil(() => loop.IsCompleted);
     Assert.True(values.All(x => x == AddressUidExtension.Uid(Sys)));
 }
开发者ID:Micha-kun,项目名称:akka.net,代码行数:11,代码来源:AddressUidExtensionSpecs.cs

示例3: GetService_can_be_accessed_from_multiple_threads_concurrently

        public void GetService_can_be_accessed_from_multiple_threads_concurrently()
        {
            for (var i = 0; i < 30; i++)
            {
                var bag = new ConcurrentBag<DbProviderServices>();
                var resolver = new DefaultProviderServicesResolver();

                ExecuteInParallel(() => bag.Add(resolver.GetService<DbProviderServices>("System.Data.SqlClient")));

                Assert.Equal(20, bag.Count);
                Assert.True(bag.All(c => SqlProviderServices.Instance == c));
            }
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:13,代码来源:DefaultProviderServicesResolverTests.cs

示例4: Should_Concurrently_Load_A_Session_And_Unlock_It_Afterwards

        public void Should_Concurrently_Load_A_Session_And_Unlock_It_Afterwards()
        {
            SessionDatabase.CreateSession(Constants.FullSessionId, ShortData);
            var store = new SqlSessionStateStore(Constants.ConnectionString, Constants.SessionTimeout);
            var results = new ConcurrentBag<bool>();

            for (var i = 0; i < 20; i++) ThreadPool.QueueUserWorkItem(
                x => results.Add((store.Load(_sessionId) ?? new byte[] {}).SequenceEqual(ShortData)));

            while (results.Count < 20) Thread.Sleep(100);

            results.All(x => x).ShouldBeTrue();
        }
开发者ID:mikeobrien,项目名称:ClassicAspRemoteSession,代码行数:13,代码来源:SqlSessionStateStoreTests.cs

示例5: TestSaveUpdatesAutoIncrementingField

 public void TestSaveUpdatesAutoIncrementingField()
 {
     //---------------Set up test pack-------------------
     ClassDef.ClassDefs.Clear();
     TestAutoInc.LoadClassDefWithAutoIncrementingID();
     var newIds = new ConcurrentBag<int?>();
     //---------------Execute Test ----------------------
     Parallel.For(0, 1000, i => {
                                    //---------------Set up test pack-------------------
                                    var bo = new TestAutoInc();
                                    bo.SetPropertyValue("testfield", "testing 123");
                                    //---------------Assert Precondition----------------
                                    Assert.IsFalse(bo.TestAutoIncID.HasValue);
                                    //---------------Execute Test ----------------------
                                    bo.Save();
                                    //---------------Test Result -----------------------
                                    newIds.Add(bo.TestAutoIncID);
     });
     //---------------Test Result -----------------------
     Assert.IsTrue(newIds.All(i => i.HasValue));
     Assert.IsTrue(newIds.All(i => i > 0));
     Assert.That(newIds.Distinct().Count(), Is.EqualTo(1000), "Every generated ID must be unique");
 }
开发者ID:Chillisoft,项目名称:habanero,代码行数:23,代码来源:TestBusinessObject_Concurrency.cs

示例6: GetService_can_be_accessed_from_multiple_threads_concurrently

        public void GetService_can_be_accessed_from_multiple_threads_concurrently()
        {
            for (var i = 0; i < 30; i++)
            {
                var bag = new ConcurrentBag<IPilkington>();
                var karl = new Karl();
                var resolver = new TransientDependencyResolver<IPilkington>(() => karl, "Karl");

                ExecuteInParallel(() => bag.Add(resolver.GetService<IPilkington>("Karl")));

                Assert.Equal(20, bag.Count);
                Assert.True(bag.All(c => karl == c));
            }
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:14,代码来源:TransientDependencyResolverTests.cs

示例7: GetService_can_be_accessed_from_multiple_threads_concurrently

        public void GetService_can_be_accessed_from_multiple_threads_concurrently()
        {
            for (var i = 0; i < 30; i++)
            {
                var bag = new ConcurrentBag<IPilkington>();
                var karl1 = new Mock<IPilkington>().Object;
                var resolver = new CompositeResolver<IDbDependencyResolver, IDbDependencyResolver>(
                    new SingletonDependencyResolver<IPilkington>(karl1),
                    new SingletonDependencyResolver<IPilkington>(new Mock<IPilkington>().Object));

                ExecuteInParallel(() => bag.Add(resolver.GetService<IPilkington>()));

                Assert.Equal(20, bag.Count);
                Assert.True(bag.All(c => karl1 == c));
            }
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:16,代码来源:CompositeResolverTests.cs

示例8: GetService_can_be_accessed_from_multiple_threads_concurrently

            public void GetService_can_be_accessed_from_multiple_threads_concurrently()
            {
                for (var i = 0; i < 30; i++)
                {
                    var bag = new ConcurrentBag<AttributeProvider>();

                    var resolver = new RootDependencyResolver();
                    resolver.AddDefaultResolver(new SingletonDependencyResolver<AttributeProvider>(new AttributeProvider()));
                    resolver.AddDefaultResolver(new SingletonDependencyResolver<AttributeProvider>(new AttributeProvider()));

                    ExecuteInParallel(() => bag.Add(resolver.GetService<AttributeProvider>()));

                    Assert.Equal(20, bag.Count);
                    Assert.True(bag.All(c => c.GetType() == typeof(AttributeProvider)));
                }
            }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:16,代码来源:RootDependencyResolverTests.cs

示例9: Main

        static void Main(string[] args)
        {
            var stopWatch = new Stopwatch();
            using (var eventStore = WireupEventStore())
            {
                Console.Write("Inserting {0} AggregateRoots with {1} commits each", AmountOfRoots, AmountOfCommitsPerRoot);
                stopWatch.Start();
                byte[] payload = new byte[80];
                var resetEvents = new ConcurrentBag<ManualResetEventSlim>();

                for (int i = 0; i < AmountOfRoots; ++i)
                {
                    if (i % (AmountOfRoots / 100) == 0)
                    {
                        Thread.Sleep(500);
                        Console.Write(".");
                    }

                    var resetEvent = new ManualResetEventSlim();
                    resetEvents.Add(resetEvent);

                    ThreadPool.QueueUserWorkItem(x =>
                    {
                        var currentRoot = Guid.NewGuid();
                        for (int commits = 0; commits < AmountOfCommitsPerRoot; ++commits)
                        {
                            using (var stream = eventStore.OpenStream(currentRoot, 0, int.MaxValue))
                            {
                                stream.Add(new EventMessage() { Body = payload });
                                stream.CommitChanges(Guid.NewGuid());
                            }
                        }

                        ((ManualResetEventSlim)x).Set();
                    }, resetEvent);
                }
                while (!resetEvents.All(x => x.IsSet))
                {
                    Thread.Sleep(100);
                }
                stopWatch.Stop();
                Console.WriteLine("done in {0} ms.", stopWatch.ElapsedMilliseconds);
                Console.ReadKey();
            }
        }
开发者ID:jvandertil,项目名称:EventStoreAzureTest,代码行数:45,代码来源:Program.cs

示例10: GetService_can_be_accessed_from_multiple_threads_concurrently

        public void GetService_can_be_accessed_from_multiple_threads_concurrently()
        {
            for (var i = 0; i < 30; i++)
            {
                var bag = new ConcurrentBag<IDatabaseInitializer<FakeContext1>>();
                var resolver = new DatabaseInitializerResolver();
                var initializer = new Mock<IDatabaseInitializer<FakeContext1>>().Object;

                ExecuteInParallel(
                    () =>
                        {
                            resolver.SetInitializer(typeof(FakeContext1), initializer);
                            bag.Add(resolver.GetService<IDatabaseInitializer<FakeContext1>>());
                        });

                Assert.Equal(20, bag.Count);
                Assert.True(bag.All(c => initializer == c));
            }
        }
开发者ID:junxy,项目名称:entityframework,代码行数:19,代码来源:DatabaseInitializerResolverTests.cs

示例11: GetService_can_be_accessed_from_multiple_threads_concurrently

        public void GetService_can_be_accessed_from_multiple_threads_concurrently()
        {
            var appConfig = new AppConfig(
                CreateEmptyConfig().AddDefaultConnectionFactory(typeof(FakeConnectionFactory).AssemblyQualifiedName));

            for (var i = 0; i < 30; i++)
            {
                var bag = new ConcurrentBag<IDbConnectionFactory>();
                var resolver = new AppConfigDependencyResolver(appConfig);

                ExecuteInParallel(() => bag.Add(resolver.GetService<IDbConnectionFactory>()));
                
                Assert.Equal(20, bag.Count);
                Assert.True(bag.All(c => resolver.GetService<IDbConnectionFactory>() == c));
            }
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:16,代码来源:AppConfigDependencyResolverTests.cs

示例12: ConfigurationThreadTest

        private static void ConfigurationThreadTest(Action<DbConfigurationManager> beforeThreads, Action<DbConfigurationManager> inThreads)
        {
            for (var i = 0; i < 30; i++)
            {
                var configurationBag = new ConcurrentBag<DbConfiguration>();
                var manager = new DbConfigurationManager(new DbConfigurationLoader(), new DbConfigurationFinder());
                beforeThreads(manager);

                ExecuteInParallel(
                    () =>
                        {
                            inThreads(manager);
                            configurationBag.Add(manager.GetConfiguration());
                        });

                Assert.Equal(20, configurationBag.Count);
                Assert.True(configurationBag.All(c => manager.GetConfiguration() == c));
            }
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:19,代码来源:DbConfigurationManagerTests.cs

示例13: Should_Return_Session_State_For_All_Classic_Concurent_Requests

 public void Should_Return_Session_State_For_All_Classic_Concurent_Requests()
 {
     var counts = new ConcurrentBag<int>();
     var session = Common.GetClassic("command=add&key=state&value=CO&datatype=String");
     for (var i = 0; i < 20; i++) ThreadPool.QueueUserWorkItem(x => counts.Add(session.GetClassic().Data.Count));
     while (counts.Count < 20) Thread.Sleep(100);
     counts.All(x => x == 1).ShouldBeTrue();
 }
开发者ID:mikeobrien,项目名称:ClassicAspRemoteSession,代码行数:8,代码来源:BridgeTests.cs

示例14: Model_hash_can_be_calculated_from_multiple_threads_using_a_single_DbCompiledModel

        public void Model_hash_can_be_calculated_from_multiple_threads_using_a_single_DbCompiledModel()
        {
            var hashes = new ConcurrentBag<string>();
            ExecuteInParallel(
                () =>
                    {
                        using (var context = new SimpleModelContext())
                        {
#pragma warning disable 612,618
                            var hash = EdmMetadata.TryGetModelHash(context);
#pragma warning restore 612,618

                            Assert.NotNull(hash);
                            hashes.Add(hash);
                        }
                    });

            Assert.True(hashes.All(h => hashes.First() == h));
        }
开发者ID:junxy,项目名称:entityframework,代码行数:19,代码来源:MultiThreadingTests.cs

示例15: EDMX_can_be_written_from_multiple_threads_using_a_single_DbCompiledModel

        public void EDMX_can_be_written_from_multiple_threads_using_a_single_DbCompiledModel()
        {
            var edmxs = new ConcurrentBag<string>();
            ExecuteInParallel(
                () =>
                    {
                        var edmxBuilder = new StringBuilder();
                        using (var context = new SimpleModelContext())
                        {
                            // Cached DbCompiledModel will be used each time
                            EdmxWriter.WriteEdmx(context, XmlWriter.Create(edmxBuilder));
                        }

                        var edmx = edmxBuilder.ToString();

                        Assert.True(edmx.Contains("EntitySet Name=\"Products\""));
                        Assert.True(edmx.Contains("EntitySet Name=\"Categories\""));

                        edmxs.Add(edmx);
                    });

            Assert.True(edmxs.All(m => edmxs.First() == m));
        }
开发者ID:junxy,项目名称:entityframework,代码行数:23,代码来源:MultiThreadingTests.cs


注:本文中的ConcurrentBag.All方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。