Updating Gui Controls from a Thread

A

Anders Fredborg

Hi !

I have experienced the problem of updating GUI controls from another Thread
runnning in an Object, the application either freezes or exits. Now, the way
I have handled this, is by having a Windows Forms Timer that checks
periodically for updates to the GUI controls. The Thread simply alters some
public variable on the Main Form by using an Event, and then the timer calls
some procedure to act accordingly.

However, Ive heard or read somewhere, that this can be done much smarter :)

I would like, that the secondary Thread running in an Object could Fire an
Event, that is handled on the main form, something like:

private void myRFnetTool_NewAdvertData(object sender,
Virtual_Shopping_Assistant.myRFUtils.AdvertEventArgs e)

{

Advert myAd;

myAd.name = e.newAdvert.name;

myAd.ownerShop = e.newAdvert.ownerShop;

adverts.Add(myAd);

showAdvert(); <-- If this procedure updates a panel, some labels
etc. with the new Advert added to adverts(ArrayList), the application
freezes


}



Can anyone help me ?

Regards

Anders
 

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

Top