This is a bit of a mistake in Winforms. It contains the diagnostic code in the getter of the Handle property, which checks that the property is used in the same stream as the one that created the handle. Although it is extremely useful to diagnose errors in streaming mode, this is not always appropriate. One such case here, Windows does not actually require the parent of the window to belong to the same thread.
You can work around this by setting SetParent () or temporarily by disabling checking with Control.CheckForIllegalCrossThreadCalls. Or using Control.Invoke (), the best way. Do not work around without specifying the owner. Due to the absence of another window, the owner of the dialog box is the desktop window. It will not have Z-order relationships with other windows that have the desktop as their owner. And this will make the dialog disappear behind another window from time to time, completely unknown to the user.
There is a big problem, although displaying dialogs on threads is an unpleasant usability problem. Turning a window into the user's face when it works with your program is a bad idea. It does not say what will happen when she clicks and types. Her accidental closure of the dialogue, without even seeing it, poses a real danger. Do not do this.
source share