private void CalculateGLCM(object parameter) { GLCMThreadParameter data = parameter as GLCMThreadParameter; if (data == null) { throw new ArgumentNullException("Неправильный параметр потока."); } for (int i = data.From; i < data.To; ++i) { var feature = GetGLCMFeature(data.Fragments[i]); data.Result.Add(feature); } data.ResetEvent.Set(); }
private List <GLCMFeature> GetSubfeatures() { var fragments = GetFragments(); int threadCount = Math.Min(fragments.Count, RecognitionParameters.FragmentProcessThreadCount); threadCount = (isMultithread) ? (threadCount) : (1); int threadPart = fragments.Count / threadCount; var resetEvents = new ManualResetEvent[threadCount]; var threadParameters = new GLCMThreadParameter[threadCount]; for (int i = 0; i < threadCount; ++i) { resetEvents[i] = new ManualResetEvent(false); threadParameters[i] = new GLCMThreadParameter( threadPart * i, ((i + 1) < threadCount) ? (threadPart * (i + 1)) : (fragments.Count), fragments, resetEvents[i]); if (threadCount > 1) { ThreadPool.QueueUserWorkItem(new WaitCallback(CalculateGLCM), threadParameters[i]); } else { CalculateGLCM(threadParameters[i]); } } WaitHandle.WaitAll(resetEvents); var list = new List <GLCMFeature>(); for (int i = 0; i < threadCount; ++i) { list.AddRange(threadParameters[i].Result); } return(list); }
private List<GLCMFeature> GetSubfeatures() { var fragments = GetFragments(); int threadCount = Math.Min(fragments.Count, RecognitionParameters.FragmentProcessThreadCount); threadCount = (isMultithread) ? (threadCount) : (1); int threadPart = fragments.Count / threadCount; var resetEvents = new ManualResetEvent[threadCount]; var threadParameters = new GLCMThreadParameter[threadCount]; for (int i = 0; i < threadCount; ++i) { resetEvents[i] = new ManualResetEvent(false); threadParameters[i] = new GLCMThreadParameter( threadPart * i, ((i + 1) < threadCount) ? (threadPart * (i + 1)) : (fragments.Count), fragments, resetEvents[i]); if (threadCount > 1) { ThreadPool.QueueUserWorkItem(new WaitCallback(CalculateGLCM), threadParameters[i]); } else { CalculateGLCM(threadParameters[i]); } } WaitHandle.WaitAll(resetEvents); var list = new List<GLCMFeature>(); for (int i = 0; i < threadCount; ++i) { list.AddRange(threadParameters[i].Result); } return list; }