0

Like the title says, I run form.ShowDialog(parentForm), where parentForm is a valid IWin32Window-inheriting form, and the opened window blocks access to the parent form (as expected), but also blocks access to my Main Form.

The only reason I can see for this is that the Main Form and the parentForm are on the same thread as the Shown Dialog. Is there any possible reason this could be occurring? And, if the problem is because of the shared thread, is there a way to resolve it without opening the dialog on a separate thread?

gemeye
  • 19
  • 1
  • How are Main Form and parentForm related? Is there an existing owner/owned or parent/child relationship between them? If so, what? – Damien_The_Unbeliever Jun 20 '17 at 07:31
  • 1
    This is how modal dialogs work in Windows (the owner is irrelevant for what gets blocked). Either show as non modal on the same thread or modal on a separate thread (just not sure if you can use an owner from another thread in the later case). – Ivan Stoev Jun 20 '17 at 09:27
  • 1
    You are liable to get yourself into a *lot* of trouble. If you don't like what ShowDialog() does then just don't use it, use Show() instead and use the FormClosing event to know that the window is about to disappear. But be sure to understand *why* ShowDialog exists and what possible bugs it avoids. Re-entrancy bugs are as nasty as threading bugs. [Read this](https://stackoverflow.com/a/5183623/17034). – Hans Passant Jun 20 '17 at 09:37
  • @Ivan Thanks, I think you're right. My approach will probably be to show a non-modal form on the current thread. – gemeye Jun 21 '17 at 00:11

1 Answers1

0

if i understand you correctly you would like to access both parent and child forms at the same time,

it will bot be possible to access parent form if you use ShowDialog()

use form.Show(parentForm) instead of form.ShowDialog(parentForm)

Vicky S
  • 762
  • 4
  • 16