[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Dynamically Create Controls on a Windows Form in an Event

Posted on 2004-04-14
7
Medium Priority
?
302 Views
Last Modified: 2010-04-15
I have an event which fires any time something is added to a collection.  On that event, I want to create a new control and add it to my form.  However, when I try an exception is thrown stating

"Controls created on one thread cannot be parented to a control on a different thread."

Anybody know any workarounds or other ways to create these controls dynamically?
0
Comment
Question by:a_goat
[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
7 Comments
 
LVL 1

Expert Comment

by:Troy_Lyne
ID: 10828466
All the Graphical components in a typical windows forms application run on a single message driven thread,  therefore all controls must be instantiated via a call from this thread.

Maybe explain a little more what you are trying to do and why your event is not part of the windows messaging thread?
0
 
LVL 3

Author Comment

by:a_goat
ID: 10832773
I'm building a web-activity driven app.  When the application starts up, a socket is opened to a server.  That socket connection is kept open and any time the server data changes, the changes are pushed down that socket to the client.  

The client has a thread which watches that socket connection.  Whenever new data comes in, that thread fires an event.  I want an event listener on that event to generate a set of controls that the user can manipulate on the form.

The architecture is set this way because everything is very time critical.  I expect to have 500 users connected to single machines in a small server farm (~5 machines).  An outside party will send their data to a central server. From there it needs to be routed to one of the farm servers which needs to route it to an individual user.  The user's machines then needs to send back an acceptance which needs to be routed all the way back up to the outside party.  The whole thing needs a round trip of less than 1/4 second.  We're hoping for around 1/10 of a second with at least 100 messages/second handled by the farm servers collectively.
0
 
LVL 3

Author Comment

by:a_goat
ID: 10834458
I found the solution.

You can call Invoke() on any control (including the form) and pass it a delegate with a list of arguments.  The delegate is then run on the control's thread.

Yay
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Expert Comment

by:Troy_Lyne
ID: 10834919
Wow, sounds like quite the application...  If my input helped in the solution please award points.  Thanks!
0
 

Expert Comment

by:denago
ID: 10839211
For those that might not get what he's saying, here is an example

// Variable declaration
public delegate void functionDelegate( string arg );
public functionDelegate function;

// Initializing the delegate int he initialization section
function = new functionDelegate( this.functionToCall );

// Then when the event is raized you call it like this.
Form1.Invoke( this.function, new obj[] { someString } );

You have you pass the arguments of the function as an object array.
0
 

Accepted Solution

by:
ee_ai_construct earned 0 total points
ID: 11756963
PAQed, with points refunded (500)
ee_ai_construct - CS Mod
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

656 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