Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Phil Price�

Visual Studio .NET 2003 Enterprise Edition

Microsoft Student Partner 2004

Microsoft Redmond, EMEA Intern 2004

  • *Gurus*
Posted

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 :)

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
Posted

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.

Visit...Bassic Software
Posted

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.

Phil Price�

Visual Studio .NET 2003 Enterprise Edition

Microsoft Student Partner 2004

Microsoft Redmond, EMEA Intern 2004

  • Moderators
Posted

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.

Visit...Bassic Software

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...