コード例 #1
0
        public void CreateInParallel()
        {
            const int Iterations = 100;
            var       dirs       = new TemporaryDirectory[Iterations];

            Parallel.For(0, Iterations, new ParallelOptions {
                MaxDegreeOfParallelism = 50
            }, i =>
            {
                dirs[i] = TemporaryDirectory.Create();
            });

            try
            {
                Assert.Equal(Iterations, dirs.DistinctBy(dir => dir.FullPath).Count());

                foreach (var dir in dirs)
                {
                    Assert.All(dirs, dir => Assert.True(Directory.Exists(dir.FullPath)));
                }
            }
            finally
            {
                foreach (var item in dirs)
                {
                    item?.Dispose();
                }
            }
        }