Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Add items to a list box from a seperate thread

Posted on 2013-05-14
3
Medium Priority
?
338 Views
Last Modified: 2013-05-15
Hello Everyone,

I figured this would be easier than it is working out to so it has to be a case that I' just can't see the trees for the forest.

On form1 I have a picture box shows an animated gif and has a listbox that I need to populate with a list of Sql Servers.

I can retrieve the list of servers without any problem except while the process is running the picture box stops and I understand why. So I created a BackgroundWorker  to handle the routine that checks for the server by using the DoWork event. That runs fine goes through and finds the servers that it is supposed and my picture boxes are doing what they are supposed to do. Just for clarity this routine is in a completely separate module.

My question is how do I  add items to my listbox from the routine that is called in the second thread that generates the list of servers. I have tried several different ways and I get all kinds of exception and delegate errors.

Thanks,
Art
0
Comment
Question by:Nashua58
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
funwithdotnet earned 1000 total points
ID: 39166979
in the DoWork method, set e.result = [object or value needed]

In the RunWorkerCompleted method, you can process e.result and do what you need.
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 1000 total points
ID: 39167495
You need to use the Progress events. You can use a class or module level variable to store the text that you want to add to listbox.

Examples here

http://www.java2s.com/Code/VB/GUI/BackgroundWorkerDemo.htm
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39167916
For future readers, the first suggestion means that items are added to the list at the end of run not during the run.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question