philprice Posted March 23, 2003 Posted March 23, 2003 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. Quote Phil Price� Visual Studio .NET 2003 Enterprise Edition Microsoft Student Partner 2004 Microsoft Redmond, EMEA Intern 2004
*Gurus* divil Posted March 23, 2003 *Gurus* Posted March 23, 2003 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 :) Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Moderators Robby Posted March 23, 2003 Moderators Posted March 23, 2003 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. Quote Visit...Bassic Software
philprice Posted March 23, 2003 Author Posted March 23, 2003 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. Quote Phil Price� Visual Studio .NET 2003 Enterprise Edition Microsoft Student Partner 2004 Microsoft Redmond, EMEA Intern 2004
Moderators Robby Posted March 23, 2003 Moderators Posted March 23, 2003 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. Quote Visit...Bassic Software
*Gurus* Derek Stone Posted March 24, 2003 *Gurus* Posted March 24, 2003 Passing parameters to a thread is fairly easy. Take a look: http://www.xtremedotnettalk.com/showthread.php?s=&threadid=70749 Quote Posting Guidelines
Moderators Robby Posted March 24, 2003 Moderators Posted March 24, 2003 Thanks for a lean solution Derek, mine circled the airport a few times. Hehe :) Quote Visit...Bassic Software
philprice Posted March 24, 2003 Author Posted March 24, 2003 thanks so much derek! :) Quote Phil Price� Visual Studio .NET 2003 Enterprise Edition Microsoft Student Partner 2004 Microsoft Redmond, EMEA Intern 2004
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.