views:

149

answers:

3

I have a WinForms app with an input textbox, button, and a multiline output textbox. A root path is entered in the textbox. Button click calls a function to recursively check all subdirectories for some proper directory naming validation check. The results are output into the multiline textbox.

If the recursive work is done in a separate class, I have two options:

  1. Keep track of improper directories in a class property(e.g. ArrayList),return the ArrayList when done, and update the output textbox with all results.

  2. Pass in ByRef the output textbox and update/refresh it for each improper directory. Even though 1 & 2 are single-threaded, with 2, I would at least get my results updated per directory.

If the recursive work is done in the presentation layer and the validation is done in a separate class, I can multithread.

Which is a cleaner way?

+2  A: 

You don't need to pass the TextBox ByRef. It's already a reference object. Passing it ByRef would only have an effect if you planned to assign a different or new TextBox to the reference.

If you're going to do the work in a separate class, it seems as simple as passing in the contents of the TextBox as a string, and getting the results back as a string or a set of strings (array or List<string> or the like). This is better than passing in the TextBox in case someday you decide to use a different kind of control to store this information.

Kyralessa
+2  A: 

I would suggest something close to option 1. I would have a method that takes the root directory as an input and returns a List of directories that are "bad". Also I would call that method on a background thread so as not to hang the UI while the operation is being performed. Add a progress bar or some sort of wait indicator so the user knows that the operation is ongoing.

Passing the textbox into the method wouldn't allow you to reuse that method for anything else. In the interest of code re-use (if that's important to you) I think it's cleaner to simply have the method return a list and let the callback method figure out how to display the data.

Snooganz
A: 

[not sure if this is the place for a follow up to the original question]

so, is it safe to say that a recursive business layer function will not be able to update a presentation level control at each recursive iteration?