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?
Thanks for any help!