getting control parenting exception in form constructor

P

Peter Jeffe

I'm getting the "Controls created on one thread cannot be parented to a
control on a different thread" exception in the field, though I've never
seen it in development or test. The odd thing is that it's coming when my
form's InitializeComponent() tries to add the first control to its
Controls collection:

System.ArgumentException: Controls created on one thread cannot be
parented to a control on a different thread.
at System.Windows.Forms.Control.ControlCollection.Add(Control value)
at System.Windows.Forms.Form.ControlCollection.Add(Control value)
at Mixzing.MixzingGUI.MainForm.InitializeComponent() in C:\Documents
and Settings\peter\My Documents\Visual Studio
2005\Projects\MixzingGUI\MixzingGUI\MainForm.Designer.cs:line 1213
at Mixzing.MixzingGUI.MainForm..ctor(Manager mgr, Player player,
Boolean standalone) in C:\Documents and Settings\peter\My Documents\Visual
Studio 2005\Projects\MixzingGUI\MixzingGUI\MainForm.cs:line 89
at Mixzing.MixzingGUI.MixzingGUI.startGUI() in C:\Documents and
Settings\peter\My Documents\Visual Studio
2005\Projects\MixzingGUI\MixzingGUI\MixzingGUI.cs:line 59

MixzingGUI is a static class whose startGUI() is newing up the MainForm
instance, which simply does:

public MainForm(Manager mgr, Player player, bool standalone) {
this.mgr = mgr;
this.player = player;
this.standalone = standalone;
mgr.Form = this;
player.Listener = this;
InitializeComponent();
[...]

and InitializeComponent() (which is completely generated by the designer)
is just doing:

this.Controls.Add(this.topBar);

So...I know that this exception may occur if I'm accessing a control from
a thread other than its creator, but at this point how could I possibly be
running on a thread other than the one that is currently creating the
form? I mean, it's right there in the stack trace--I'm running in the
same thread as the form's constructor, right? So what am I missing?
 
Z

Zhi-Xin Ye [MSFT]

Hi Peter,

I'm the Newsgroup support engineer, my name is Zhi-Xin Ye, I'm glad to work
with you on this issue.The code you posted seems OK, to help you find the
root cause, would you please send me a sample code to reproduce the
problem? My email is: (e-mail address removed).

I'm looking forward to hearing from you.

Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Z

Zhi-Xin Ye [MSFT]

Hi Peter,

May I ask if you still have any concerns on this issue? If you still need
help on this issue, please feel free to let me know, I will be happy to be
of assistance.

Have a great day!

Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Jeffe

Hi Ye,

Thanks for your offer to help. Actually, with the help of the MSDN
group moderator I was able to discern that there might be a race
condition with another thread accessing the form before it was fully
constructed, so hopefully that fixed it. I'll certainly come back if
not. Thanks for your help!
 
Z

Zhi-Xin Ye [MSFT]

Hi Peter,

May I know the status of this issue now? Just hope everything is going on
well. If you still need help on this issue, please don't hesitate to let me
know.

Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can

improve the support we provide to you. Please feel free to let my manager
know what you think of the level

of service provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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