multithreading - process files in parallel C# -
I have this code that reads all the words from the file and specifies the ID for each unique word and it's in a dictionary I need to run it in parallel to increase the efficiency of the application. I tried to use foreach
instead of parallel.ForEach
, but the efficiency has not increased using the lock to add new words and IDs. Can you help people tell me this by telling me how can I explain this code parallel?
// Fixed Object Locker = New Object (); String [] fnames; File files are collected by saving the file. & Lt; String, index entry & gt; ID = new dictionary & lt; String, index entry & gt; (); Foreach (var fname in the format) {string [] line = file. Readlline (FNA); For (int i = 0; i & lt; lines.Length; i ++) {string [] Raw = Regex.Split (line [i], @ "\ w +"); For (int j = 0; j end lie; raw; langeth; j ++) {string z = raw [j]; If (id! Kantsenseake (jade)) {id.ed (z, new index indicator); }}
If the code for this block is accessed by multiple thread ID then ID The first concurrent believes the dictionary, which thread is safe, will implement locking for you.
Edit:
Comments
Post a Comment