/// <summary> /// Using multiple threads loops through the useragents in the file /// provided perform a match with the data set provided passing /// control back to the method provided for further processing. /// </summary> /// <param name="provider"></param> /// <param name="userAgents"></param> /// <param name="method"></param> /// <returns>Counts for each of the methods used</returns> internal static Results DetectLoopMultiThreaded(Provider provider, IEnumerable<string> userAgents, ProcessMatch method, object state) { provider.DataSet.ResetCache(); var results = new Results(); Parallel.ForEach(userAgents, line => { var match = provider.Match(line.Trim()); method(results, match, state); Interlocked.Increment(ref results.Count); lock (results.Methods) { results.Methods[match.Method] = results.Methods[match.Method] + 1; } }); AssertPool(provider); ReportMethods(results.Methods); ReportProvider(provider); ReportTime(results); return results; }
/// <summary> /// In a single thread loops through the useragents in the file /// provided perform a match with the data set provided passing /// control back to the method provided for further processing. /// </summary> /// <param name="provider"></param> /// <param name="userAgents"></param> /// <param name="method"></param> /// <returns>Counts for each of the methods used</returns> internal static Results DetectLoopSingleThreaded(Provider provider, IEnumerable<string> userAgents, ProcessMatch method, object state) { provider.DataSet.ResetCache(); var match = provider.CreateMatch(); var results = new Results(); foreach (var line in userAgents) { provider.Match(line.Trim(), match); method(results, match, state); results.Count++; results.Methods[match.Method]++; } AssertPool(provider); ReportMethods(results.Methods); ReportProvider(provider); ReportTime(results); return results; }
/// <summary> /// In a single thread loops through the useragents in the file /// provided perform a match with the data set provided passing /// control back to the method provided for further processing. /// </summary> /// <param name="provider"></param> /// <param name="userAgents"></param> /// <param name="method"></param> /// <returns>Counts for each of the methods used</returns> internal static Results DetectLoopSingleThreaded(Provider provider, IEnumerable <string> userAgents, ProcessMatch method, object state) { provider.DataSet.ResetCache(); var match = provider.CreateMatch(); var results = new Results(); foreach (var line in userAgents) { provider.Match(line.Trim(), match); method(results, match, state); results.Count++; results.Methods[match.Method]++; } AssertPool(provider); ReportMethods(results.Methods); ReportProvider(provider); ReportTime(results); return(results); }
/// <summary> /// Using multiple threads loops through the useragents in the file /// provided perform a match with the data set provided passing /// control back to the method provided for further processing. /// </summary> /// <param name="provider"></param> /// <param name="userAgents"></param> /// <param name="method"></param> /// <returns>Counts for each of the methods used</returns> internal static Results DetectLoopMultiThreaded(Provider provider, IEnumerable <string> userAgents, ProcessMatch method, object state) { provider.DataSet.ResetCache(); var results = new Results(); Parallel.ForEach(userAgents, line => { var match = provider.Match(line.Trim()); method(results, match, state); Interlocked.Increment(ref results.Count); lock (results.Methods) { results.Methods[match.Method] = results.Methods[match.Method] + 1; } }); AssertPool(provider); ReportMethods(results.Methods); ReportProvider(provider); ReportTime(results); return(results); }
/// <summary> /// Using multiple threads loops through the useragents in the file /// provided perform a match with the data set provided passing /// control back to the method provided for further processing. /// </summary> /// <param name="provider"></param> /// <param name="userAgents"></param> /// <param name="method"></param> /// <param name="state"></param> /// <param name="silent"></param> /// <returns>Counts for each of the methods used</returns> internal static Results DetectLoopMultiThreaded(IWrapper provider, IEnumerable <string> userAgents, ProcessMatch method, object state, bool silent = false) { var results = new Results(); Parallel.ForEach(userAgents, line => { try { using (var match = provider.Match(line.Trim())) { method(results, match, state); } Interlocked.Increment(ref results.Count); } catch (AccessViolationException ex) { Console.WriteLine(line); Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } }); if (!silent) { ReportTime(results); } return(results); }
/// <summary> /// In a single thread loops through the useragents in the file /// provided perform a match with the data set provided passing /// control back to the method provided for further processing. /// </summary> /// <param name="provider"></param> /// <param name="userAgents"></param> /// <param name="method"></param> /// <param name="state"></param> /// <param name="silent"></param> /// <returns>Counts for each of the methods used</returns> internal static Results DetectLoopSingleThreaded(IWrapper provider, IEnumerable <string> userAgents, ProcessMatch method, object state, bool silent = false) { var results = new Results(); foreach (var line in userAgents) { try { using (var match = provider.Match(line.Trim())) { method(results, match, state); } } catch (AccessViolationException ex) { Console.WriteLine(line); Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } results.Count++; } if (!silent) { ReportTime(results); } return(results); }
/// <summary> /// In a single thread loops through the useragents in the file /// provided perform a match with the data set provided passing /// control back to the method provided for further processing. /// </summary> /// <param name="provider"></param> /// <param name="userAgents"></param> /// <param name="method"></param> /// <returns>Counts for each of the methods used</returns> internal static Results DetectLoopSingleThreaded(IWrapper provider, IEnumerable<string> userAgents, ProcessMatch method, object state) { var results = new Results(); foreach (var line in userAgents) { try { using (var match = provider.Match(line.Trim())) { method(results, match, state); } } catch (AccessViolationException ex) { Console.WriteLine(line); Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } results.Count++; } ReportTime(results); return results; }
/// <summary> /// Using multiple threads loops through the useragents in the file /// provided perform a match with the data set provided passing /// control back to the method provided for further processing. /// </summary> /// <param name="provider"></param> /// <param name="userAgents"></param> /// <param name="method"></param> /// <returns>Counts for each of the methods used</returns> internal static Results DetectLoopMultiThreaded(IWrapper provider, IEnumerable<string> userAgents, ProcessMatch method, object state) { var results = new Results(); Parallel.ForEach(userAgents, line => { try { using (var match = provider.Match(line.Trim())) { method(results, match, state); } Interlocked.Increment(ref results.Count); } catch(AccessViolationException ex) { Console.WriteLine(line); Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } }); ReportTime(results); return results; }
private List <AllFilesClass> GetDelete(int count, int threadsCount, List <AllFilesClass> list, string pattern, ICollection <AllFilesClass.ExtType> typesFind, ProcessMatch processMatch) { var cnt = new IntToRefType { Count = 0 }; _threadsList = new List <Thread>(); var part = count / threadsCount; for (var i = 0; i < threadsCount; i++) { _threadsList.Add(new Thread(GetDelete)); BMTools.BmDebug.Debug.Info("start thread=", i, "count=", count, "skip=", part * i, "take=", i != threadsCount - 1 ? part : count - part * i); _threadsList[i].Start(new SendToThreadClass { Count = count, List = list, Pattern = pattern, TypesFind = typesFind, ProcessMatch = processMatch, Counter = cnt, Skip = part * i, Take = i != threadsCount - 1 ? part : count - part * i }); } for (var i = 0; i < threadsCount; i++) { if (_threadsList[i].IsAlive) { _threadsList[i].Join(); } } return(list); }