Exemplo n.º 1
0
        /// <summary>
        /// Parallel decompress
        /// </summary>
        protected void DecompressParallel()
        {
            //Create thread pool
            var tPool = new ThreadsManager(base._totalThreads);

            try
            {
                Thread readThread = new Thread(this.ReadFromFile);
                readThread.Start();
                Thread writeThread = new Thread(this.WriteToFile);
                writeThread.Start();

                for (int i = 0; i < base._totalThreads; i++)
                {
                    tPool.AddThread(DataProcessing);
                }
                tPool.StartThreads();

                tPool.WaitAll();

                IsWorkComplete = true;

                writeThread.Join();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                tPool.Dispose();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Parallel compressing
        /// </summary>
        protected void CompressParallel()
        {
            //Create pool of threads
            var tPool = new ThreadsManager(base._totalThreads);

            try
            {
                //Thread for reading
                Thread readThread = new Thread(this.ReadFromFile);
                readThread.Start();
                //Thread for writing
                Thread writeThread = new Thread(this.WriteToFile);
                writeThread.Start();

                //Add threads
                for (int i = 0; i < base._totalThreads; i++)
                {
                    tPool.AddThread(DataProcessing);
                }

                //Start threads
                tPool.StartThreads();

                //Waiting
                tPool.WaitAll();

                IsWorkComplete = true;

                //Wait finish write
                writeThread.Join();
            }
            finally
            {
                tPool.Dispose();
            }
        }