Threading Issue

  • Thread starter Thread starter paulg
  • Start date Start date
P

paulg

hi
I am new to dot net. The problem I am having now is that I would like a
thread to feed data from database to a arraylist at background and at the
same time I want to display the objects in the arraylist in a form.

The brief code is:

private ArrayList CustomerList;
public Form_Load(){

Thread loadThread = new Thread(new ThreadStart(Loaddata));
loadThread.Start();
DisplayData();
....
....
}
private void LoadData(){
//get customer objects from database and add them to arrayList
}
private void DisplayData(){
Customer c = (Customer)CustomerList[0];
this.txtFirstName=c.FirstName;
.....
}


However I got exception:"Error creating windows handler,
OutOfMemoryException.

Can someone please point me what the problem is and how to get around it?
Thanks in Advance.
 
First make sure that creating the window works without the extra thread, e.g
by commenting out the thread lines.

If that works, make sure that you do not call any methods on the form or any
of its control from the extra thread. All such calls must be made on the
thread that created the form or control. A useful method might be
Control.InvokeRequired.

Finally, if you use an intermediate array, make sure that the different
threads are properly synchronized, when accessing the array, e.g. by using
Monitor or Mutex objects.

Best regards,
Manfred.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top