Threading

philprice

Centurion
Joined
Mar 21, 2003
Messages
116
Location
Hull, UK
Right ive got a question / problem with threading.

Ive made a thread object, but my first moan is that you cant pass paramaters to methods that you thread - why? Secondly What I want to do is create 5 threads that will each download a site and add it to my treeview, then when the thread is over go onto the next site, etc etc, so the user will not be "locked up" as sites download to the PocketPC (making a simple RSS reader to learn .NET fully). How would i impliment this, i managed to thread a loadAllSites() method, but it threw an exception when i tried to add stuff to the treeview and I don't fully understand why - I'm pretty new to actually programming threading.

Thanks in advance.
 
You can't pass parameters to a thread because that's just not how they work. I haven't used them much myself, so I can't really comment further on that.

As far as an exception being raised, I can help you with that. You shouldn't (and cannot) interact with UI controls from a thread other than the one they were created on. You need to put the code you want to run in the UI thread in a procedure that matches a delegate, and use Control.Invoke to run that delegate. Sounds tricky I know, and it is until you've done it, then you get used to it :)
 
Phile, what parameter do you want to pass, URL of sites to download? If so where is this list coming from?

I think we can keep the threading aspect alive while changing some of the backend stuff.
Can you spell out what the thread itself is doing.
 
Basically i have a list of sites from a webservice, then i want my RSSGet.getFeed() method and the fillTreeView() method to be threaded off so it can download nicely and no user waiting as a bunch of stuff downloads.

The least i want is for the sites to download one by one, but the user can still look through the data thats been got.
 
One way is to let the GetFeed take care of what's been loaded or not.

And before doing a Thread.Start you can verify how many items are in the service list.

If this doesn't make sense to you, let me know.
 
Back
Top