c# - When to register a method that will call Form.Invoke to an event? -
i following exception in windows form application
system.invalidoperationexception: invoke or begininvoke cannot called on control until window handle has been created.
the method exception occurs calls this.invoke (system.windows.forms.form.invoke). method registered event of class in constructor, seems lead race condition , exception.
public form1() { initializecomponent(); someotherclass.instance.myevent += new somedelegate(mymethod); } private void mymethod() { this.invoke((methodinvoker)delegate { // ... code ... } } at stage of form lifecycle handle created? in event of form safe register method foreign event?
i think if register method in onshow event should safe.
Comments
Post a Comment