?
Solved

Creating controls from Async Callbacks

Posted on 2005-03-31
3
Medium Priority
?
551 Views
Last Modified: 2012-06-27

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
Comment
Question by:ACanadian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 10

Expert Comment

by:eternal_21
ID: 13675212
You want to create a control, and add it to the form?
0
 
LVL 10

Accepted Solution

by:
eternal_21 earned 1000 total points
ID: 13675255
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
 

Author Comment

by:ACanadian
ID: 13676941

Thank you very much!

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

Thanks again... perfect answer.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question