[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 552
  • Last Modified:

Creating controls from Async Callbacks


Hey Experts,

I am looking for some more information about Async Callbacks.

Do they run on the ui thread that the Async method was called from or do they run on a seperate thread?

I am assuming that they run on a seperate thread because if I attempt to create windows controls and display it doesn't work.  Assuming this is correct how would you get the main ui thread to create something for you after a callback has fired?

Thanks in advance!

ACanadian
0
ACanadian
Asked:
ACanadian
  • 2
1 Solution
 
eternal_21Commented:
You want to create a control, and add it to the form?
0
 
eternal_21Commented:
If I understand you right, you can use this code in your form class:

  private delegate void AddControlHandler(Control control);

  public void InvokeAddControl(Control control)
  {
    Invoke(new AddControlHandler(AddControl), new object[] {control});
  }

  private void AddControl(Control control)
  {
    Controls.Add(control);
  }

And then from your Async callback, or any other thread, you can do:

  InvokeAddControl(newControl);

where 'newControl' is the new control that you are adding to the form (initialized, and properties such as Location set, etc.).
0
 
ACanadianAuthor Commented:

Thank you very much!

I needed to know that Invoke calls the function on the owning thread.

Thanks again... perfect answer.
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now