c#:
[quoted text, click to view] "Peter Thornqvist" <peter.tornqvist@gmail.com> wrote in message
news:urhI9kQAHHA.1224@TK2MSFTNGP04.phx.gbl...
> 1. Where do I implement the threading? In the app/class calling the
> filesearcher class or in the filesearcher class directly?
If you want the class to present an async interface to any client, then put
the threading in the class itself. If not, then wrap the class with some
threading functionality in the client.
You can do it either way. Personally, I'd go ahead and build the threading
into the class. That makes things a little cleaner and reusable. But
there's no mandate that it be done one way or the other.
[quoted text, click to view] > 2. How do I make the events synchronuos? I need to wait for their
> completion since I need the Cancel parameter.
When your background thread calls an event handler, that happens on the
background thread, synchronously with anything else that happens in the
thread.
There are other ways to run an event handler, but this is the way it happens
in the simplest case. So your background thread would simply call the event
handler normally, check the Cancel parameter on return and behave
accordingly.
Of course, this means that the handlers registered with your class should
not take too much time to do anything. They should pretty much just note
the information as desired, set the Cancel flag if necessary, and return as
soon as possible. Otherwise, the entire background thread gets held up.
[quoted text, click to view] > 3. Is there an alternative to using a Cancel parameter in the event args?
Depends on what behavior you want. But sure, there's lots of other ways you
could inform the background thread to stop searching, if that's what you
want.
[quoted text, click to view] > 4. If implementing threading in the filesearcher class is the best way to
> proceed, can I still maintain the synchronuos behavior already
> implemented?
What synchronous behavior are you trying to maintain? You need not require
the class client to use the async behavior if you don't want do. Making it
optional should not be difficult, if that's what you mean.
Pete