How to start a process and make its main window modal for the window of the initial process?

I have a C # WinForms program that starts another process. The program then waits for the process to complete.

I am currently using Process.WaitForExit (), but this means that while my program is waiting for the process to complete, it does not redraw and looks like it is not responding.

Is there any way for the window of the process that my program starts to be modal to my main form (i.e. you cannot go back to my program and redraw the windows)?

Basically, I want to do something like Form.ShowDialog (), except that the process window is a form that will be displayed as a dialog.

+3
source share
8 answers

Why don't you start your process in a separate thread? Thus, only your thread will wait. That way your form will still respond.

+1
source

You cannot prevent the user from switching because you created a separate process. As for the operating system, this means that you launched the second through the desktop icon (for example).

I think that the best thing you can hope for is to disable the corresponding menus / options when the second process is active. You will need to continue the survey to make sure it is still alive, otherwise your main application will become unusable.

Another approach may be to minimize the main application, which will hamper it.

+1
source

, . BackgroundWorker, RunWorkerCompleted, .

0

, . Visible = false;, , .

a BeginInvoke(new MethodInvoker(delegate { Close(); } )); .

0

, , . ,

0
  • process.Exited, , .
  • ( ) . , .
0

, . SetParent () child/parent, . . perl, SetParent(), , , .

0

, , . ProcessActive. , , , , . ProcessActive True . Exited , ProcessActive False. , . , . , , , .

0

Source: https://habr.com/ru/post/1753536/


All Articles