I have a scenario where I need to search from many binary files (using keys) and combine the results (strings). Until now, I have been doing it in a for loop one file after the other.
foreach (string file in FileSources.Keys)
{
aggregatedDefinitions.Append(DefinitionLookup(txtSearchWord.Text, file));
}
Since this operation is very slow, I was thinking of using threads, so that I could do IO operations in parallel. Is threading the right way to go. If I use threading, how can I ensure that I get the results in the order I want.
I haven’t used Threading until now. It would be very helpful if you could suggest some materials/books that would help me solve my problem.
Generally speaking, it’s advised to use threading for I/O operations when you’re performing one I/O operation on a separate thread from an application’s main (typically, GUI) thread. To split many I/O operations off on separate threads in parallel probably isn’t going to help you, since the disk can only be accessed by one at a time.