I get the following exception in a windows form application
System.InvalidOperationException: Invoke or BeginInvoke cannot be called in a control until a window handle is created.
The method in which the exception is thrown calls this.Invoke (System.Windows.Forms.Form.Invoke). This method is registered in the event of another class in the constructor, which, apparently, leads to the race condition and this exception.
public Form1() { InitializeComponent(); SomeOtherClass.Instance.MyEvent += new SomeDelegate(MyMethod); } private void MyMethod() { this.Invoke((MethodInvoker)delegate {
At what stage in the life cycle of a form is Handle created? In which case would it be safe to register a method for a foreign event?
Hinek source share