Beispiel #1
0
        /// <summary>
        ///
        /// </summary>

        private void ThreadPro()
        {
            ThreadHelper.AssignToCPU(CPUAssignHelper.Helper.CPUArray2);
            while (!mIsClosed)
            {
                try
                {
                    resetEvent.WaitOne();
                    lock (resetEvent)
                    {
                        resetEvent.Reset();
                    }

                    //#if DEBUG
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    LoggerService.Service.Info("Compress", "********开始执行压缩********", ConsoleColor.Blue);
                    //#endif

                    if (mSourceMemorys.Count > 0)
                    {
                        while (mSourceMemorys.Count > 0)
                        {
                            HisDataMemoryBlockCollection3 sm;
                            lock (mSourceMemorys)
                                sm = mSourceMemorys.Dequeue();

                            while (CheckIsBusy())
                            {
                                LoggerService.Service.Warn("Compress", "压缩出现阻塞");
                                Thread.Sleep(500);
                            }

                            System.Threading.Tasks.Parallel.ForEach(mTargetMemorys, new ParallelOptions()
                            {
                                MaxDegreeOfParallelism = CPUAssignHelper.Helper.CPUArray2.Length
                            }, (mm) =>
                            {
                                ThreadHelper.AssignToCPU(CPUAssignHelper.Helper.CPUArray2);
                                mm.Value.Compress(sm);
                            });

                            HisDataMemoryQueryService3.Service.ClearMemoryTime(sm.CurrentDatetime);
                            sm.Clear();
                            sm.MakeMemoryNoBusy();


                            System.Threading.Tasks.Parallel.ForEach(mTargetMemorys.Where(e => e.Value.HasManualCompressItems), new ParallelOptions()
                            {
                                MaxDegreeOfParallelism = CPUAssignHelper.Helper.CPUArray2.Length
                            }, (mm) =>
                            {
                                ThreadHelper.AssignToCPU(CPUAssignHelper.Helper.CPUArray2);
                                mm.Value.ManualCompress();
                            });
                        }
                    }
                    else
                    {
                        System.Threading.Tasks.Parallel.ForEach(mTargetMemorys.Where(e => e.Value.HasManualCompressItems), (mm) =>
                        {
                            ThreadHelper.AssignToCPU(CPUAssignHelper.Helper.CPUArray2);
                            mm.Value.ManualCompress();
                        });
                    }

                    //#if DEBUG
                    sw.Stop();
                    LoggerService.Service.Info("Compress", ">>>>>>>>>压缩完成>>>>>>>>>" + " ElapsedMilliseconds:" + sw.ElapsedMilliseconds, ConsoleColor.Blue);
                    //#endif

                    ServiceLocator.Locator.Resolve <IDataSerialize3>().RequestToSave();
                }
                catch (Exception ex)
                {
                    LoggerService.Service.Erro("Compress", ex.Message + ex.StackTrace);
                }

                if (mIsClosed)
                {
                    break;
                }
            }
            closedEvent.Set();

            LoggerService.Service.Info("Compress", "压缩线程退出!");
        }