/// <summary> /// Iterates through the given file list an spawn a new thread per file for peforming the RegEx search. /// </summary> /// <param name="FileList"></param> /// <param name="SearchTermList"></param> /// <param name="Crawler"></param> /// <returns></returns> public List<Finding> Iterate(List<FileInfo> FileList, List<RegExSearchTerm> SearchTermList, IRegExCrawler Crawler) { var start = DateTime.Now; resultQueue = new System.Collections.Queue(); var chunkedFileLists = ChunkBy(FileList, maxThreads); foreach (var chunkedList in chunkedFileLists) { SpawnThreads(chunkedList, SearchTermList, Crawler); } var duration = DateTime.Now - start; System.Diagnostics.Trace.TraceInformation(String.Format("Duration: {0}:{1}:{2} ", duration.Hours, duration.Minutes, duration.Seconds)); var resultList = new List<Finding>(); //for (int i = 0; i <= resultQueue.Count; i++) while (resultQueue.Count > 0) { System.Diagnostics.Trace.TraceInformation(String.Format("ResultQueueCount: {0} ", resultQueue.Count)); resultList.AddRange((List<Finding>)resultQueue.Dequeue()); } System.Diagnostics.Trace.TraceInformation(String.Format("ResultListCount: {0} ", resultList.Count)); return resultList; }
private void SpawnThreads(List <FileInfo> FileList, List <RegExSearchTerm> SearchTermList, IRegExCrawler Crawler) { var threadCount = FileList.Count(); manualEvents = new ManualResetEvent[threadCount]; foreach (var file in FileList) { var currentIndex = FileList.IndexOf(file); System.Diagnostics.Trace.TraceInformation(String.Format("threadCount: {0}, currentIndex: {1} current File: {2}", threadCount, currentIndex, file.FullName)); manualEvents[currentIndex] = new ManualResetEvent(false); ThreadPool.QueueUserWorkItem(DoWork, new object[] { file, SearchTermList, Crawler, manualEvents[currentIndex] }); } WaitHandle.WaitAll(manualEvents); }
private void SpawnThreads(List<FileInfo> FileList, List<RegExSearchTerm> SearchTermList, IRegExCrawler Crawler) { var threadCount = FileList.Count(); manualEvents = new ManualResetEvent[threadCount]; foreach (var file in FileList) { var currentIndex = FileList.IndexOf(file); System.Diagnostics.Trace.TraceInformation(String.Format("threadCount: {0}, currentIndex: {1} current File: {2}", threadCount, currentIndex, file.FullName)); manualEvents[currentIndex] = new ManualResetEvent(false); ThreadPool.QueueUserWorkItem(DoWork, new object[] { file, SearchTermList, Crawler, manualEvents[currentIndex] }); } WaitHandle.WaitAll(manualEvents); }
/// <summary> /// Iterates through the given file list an spawn a new thread per file for peforming the RegEx search. /// </summary> /// <param name="FileList"></param> /// <param name="SearchTermList"></param> /// <param name="Crawler"></param> /// <returns></returns> public List <Finding> Iterate(List <FileInfo> FileList, List <RegExSearchTerm> SearchTermList, IRegExCrawler Crawler) { var start = DateTime.Now; resultQueue = new System.Collections.Queue(); var chunkedFileLists = ChunkBy(FileList, maxThreads); foreach (var chunkedList in chunkedFileLists) { SpawnThreads(chunkedList, SearchTermList, Crawler); } var duration = DateTime.Now - start; System.Diagnostics.Trace.TraceInformation(String.Format("Duration: {0}:{1}:{2} ", duration.Hours, duration.Minutes, duration.Seconds)); var resultList = new List <Finding>(); //for (int i = 0; i <= resultQueue.Count; i++) while (resultQueue.Count > 0) { System.Diagnostics.Trace.TraceInformation(String.Format("ResultQueueCount: {0} ", resultQueue.Count)); resultList.AddRange((List <Finding>)resultQueue.Dequeue()); } System.Diagnostics.Trace.TraceInformation(String.Format("ResultListCount: {0} ", resultList.Count)); return(resultList); }