Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Add items to a list box from a seperate thread

Posted on 2013-05-14
3
Medium Priority
?
343 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
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .

886 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