private void GenerateAndMergeFilesAsync(UniqueRandom uniqueRandom)
        {
            var inputFileDetails = new FileDetails(this.Input);

            this.GenerateFiles(uniqueRandom, inputFileDetails);
            this.MergeFiles(inputFileDetails, uniqueRandom.SubRanges.Count);
        }
 private void GenerateRandomNumbersFromRangesSequentially(UniqueRandom uniqueRandom, FileDetails fileDetails)
 {
     for (var i = 0; i < uniqueRandom.SubRanges.Count; i++)
     {
         var subRange   = uniqueRandom.SubRanges[i];
         var threadData = new ThreadData()
         {
             FileDetails = fileDetails,
             Range       = subRange,
             RangeIndex  = i
         };
         ThreadPool.QueueUserWorkItem(this.WriteNumbersToDiskFileForSubRanges, threadData);
     }
 }
        private void GenerateFiles(UniqueRandom uniqueRandom, FileDetails fileDetails)
        {
            ThreadPool.SetMaxThreads(10, 10);

            GenerateRandomNumbersFromRangesRandomly(uniqueRandom, fileDetails);
            //GenerateRandomNumbersFromRangesSequentially(uniqueRandom, fileDetails);

            int workerThreads, portThreads;

            ThreadPool.GetAvailableThreads(out workerThreads, out portThreads);

            while ((workerThreads < 10) || (portThreads < 10))
            {
                Thread.Sleep(10);
                ThreadPool.GetAvailableThreads(out workerThreads, out portThreads);
            }
        }
        public override void GenerateInput()
        {
            Console.Write("Enter min value: ");
            var minValue = int.Parse(Console.ReadLine());

            Console.Write("Enter max value: ");
            var maxValue = int.Parse(Console.ReadLine());

            this.MeasureTimeStart(MethodBase.GetCurrentMethod().Name, "Create unique random number object");

            var uniqueRandom = new UniqueRandom(minValue, maxValue);

            this.MeasureTimeEnd(MethodBase.GetCurrentMethod().Name, "unique random number object creation");
            this.MeasureTimeStart(MethodBase.GetCurrentMethod().Name, "Generate file with unique random numbers");

            this.GenerateAndMergeFilesAsync(uniqueRandom);

            this.MeasureTimeEnd(MethodBase.GetCurrentMethod().Name, "writing unique random numbers");
        }
        private void GenerateRandomNumbersFromRangesRandomly(UniqueRandom uniqueRandom, FileDetails fileDetails)
        {
            var randomSubRange = new NumberRange(0, uniqueRandom.SubRanges.Count);
            var randomIndex    = randomSubRange.NextUnique();
            var fileIndex      = 0;

            while (randomIndex != null)
            {
                var subRange   = uniqueRandom.SubRanges[(int)randomIndex];
                var threadData = new ThreadData()
                {
                    FileDetails = fileDetails,
                    Range       = subRange,
                    RangeIndex  = fileIndex++
                };
                ThreadPool.QueueUserWorkItem(this.WriteNumbersToDiskFileForSubRanges, threadData);
                randomIndex = randomSubRange.NextUnique();
            }
        }