asynch call back and adding controls

  • Thread starter Thread starter Lance Johnson
  • Start date Start date
L

Lance Johnson

I have an asynch call setup and a callback for it. During the callback I
want to be able to add controls to my form. However, it appears it's
working in the context of the asynchronous thread. Has anybody had this
problem and what can I do so I can add controls to my form after this
occurs.

Lance Johnson
 
You need to call the Invoke() method on the Form you want to add
controls to, within your callback method.

Within your callback, have something like this:
(assumes callback is defined in the form class)


private void MyCallBack(){
if (this.InvokeRequred){
// running on a different thread, need to invoke on form's thread
this.Invoke(myCallBackDelegate);
}
// this part is guaranteed to run in the form's thread
// do work to add controls to form
}
 

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