Hi,how can I grab information from url or darabase using threads and set the returned information in one listbox using c#??
I tried to do that but the error is :
the listbox cann't give the control for adding items to more than one thread.
I want the result set from all threads to be in the listbox....
thanx alot
Eng.Bilal Salas
Loading
Amit ChoudharyPosted Jul 5, 2010, 12:51 AM
try this:
while updating items in list box use lock:
{
lock(dropdownlist1)
{
// your updating statement here
}
}
use this statement in every thread you are updating the list and your problem will be solve but use it carefully.....
wrong use can bring you to deadlock situations..
Please mark as answer if it helps you.
Sam HobbsPosted Jul 5, 2010, 3:06 AM
Use BackgroundWorker; look for articles about it in this web site and other places; there are many articles.
Use the BackgroundWorker.DoWork event to do the work; that is, to "grab information from url or darabase". I think that in the other thread (in the DoWork event) you should add items to a collection such as an ArrayList; the collection could be a member of the form. In the BackgroundWorker.RunWorkerCompleted event, add the items from the collection to the ListBox.
The ListBox could be bound to the collection, but if you don't understand that then ignore it.