C# Threading
-
Hi , I am trying to create an application to extract some txt files from ZIP and then search the text files for a search string. I have done two functions 1. That extracts the files 2. That searches through the files This is my required program flow. I need to threads to run here The first thread should concentrate on searching the file, extracting them and add the extracted files's to a string array and the second thread to monitor that string array and search the newly added files for the search string. Is this possible? I have done some coding for this. Will post it later in this message thread if required later.
Jack Sparrow -------------------------------------- Defeat is not the worst of failures. Not to have tried is the true failure.
-
Hi , I am trying to create an application to extract some txt files from ZIP and then search the text files for a search string. I have done two functions 1. That extracts the files 2. That searches through the files This is my required program flow. I need to threads to run here The first thread should concentrate on searching the file, extracting them and add the extracted files's to a string array and the second thread to monitor that string array and search the newly added files for the search string. Is this possible? I have done some coding for this. Will post it later in this message thread if required later.
Jack Sparrow -------------------------------------- Defeat is not the worst of failures. Not to have tried is the true failure.
Ramkithepower wrote:
Is this possible?
Yes - I'm not sure it's the best possible design, but it is possible. What you could do (if you are using .NET 3.5 or later) is use an
ObservableCollection
in the first thread which the second thread hooks into the event handlers for to see when items are added into that collection - then it can perform it's searching in response to the item changing. Alternatively, and this is perhaps a better method, you could have your first thread implement an event handler that takes the contents of the file as a parameter (assuming you are just storing it as a big string here) and the second thread hooks into that event. Obviously, you'd fire off the event every time you added a file.I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be
Forgive your enemies - it messes with their heads