c# - What's wrong with my cross-thread call in Windows Forms? -
I have a problem with a Windows Forms application.
One form should be displayed with another thread. So in the form class, I have the following code:
Personal representative Zero DisplayDialogCallback (); Public Zero Display Deletion () (if (this.InvokeRequired) {this.Invoke (New DisplayDialogCallback (DisplayDialog))} and (This ShowDialog ();}}
Now, every Once I run it, a invalid operation exception
is inserted on the line . ShowDialog ();
:
"Cross-Thread The operation is not valid: Control 'SampleForm' was created from the thread that was created on it. "
What's wrong with this code piece? Is it a cross-thread call Why a valid Is not a special effort on this? ShowDialog () ?
Please:
Personal representative Zero DisplayDialogCallback (); Public Zero Display Deletion () (if (this.InvokeRequired) {this.Invoke (New DisplayDialogCallback (DisplayDialog))} Else {if ( This.Handle! = (IntPtr) 0) // You can also use it: It is .hadle ready (ShowDialog this); if (this.CanFocus) {this.Focus ();}} and {// Error handle}}}
Please note that InvokeRequired
returns
is correct if there are controls Dul was created on a separate thread from the calling thread (this indicates that you have to call for control through an invoice method); Otherwise, wrong.
Comments
Post a Comment