2

I'm starting a external application with System.Diagnostics.Process, this external process at one moment opens up a dialog where user has type something and then click OK. What i need is to wait with my application(the one where i started the external process) until the user has inserted something and clicked OK. After that OK i have to do some more task on that external process and then close it.

hs2d
  • 6,027
  • 24
  • 64
  • 103

3 Answers3

1

Yes, it's possible. There are a number of ways to get window information starting with a process handle and/or ID. See this question and responses for getting started. You will most likely end up using P/Invoke to the Win32 API to get this accomplished but there are dozens of good examples for getting this done.

Once you have the window handle you can use a timer polling scheme to test for the presence, or in your case, presence and then the disappearance of a window.

Community
  • 1
  • 1
Paul Sasik
  • 79,492
  • 20
  • 149
  • 189
1

This is possible but there are some work behind it. First you need to run your code as unmanaged code as you will need to hook on Windows OS events with the Win32 API.

So an option would be to have a loop looking for the dialog to open, pause what ever your code are doing and continue when the dialog are gone.

StefanE
  • 7,578
  • 10
  • 48
  • 75
0

If the application you are starting exists after the user interacts with the dialog, then you can just call Process.WaitFroExit() and your code will not continue until the process you started has quit.

There are quite a few helpful functions for interacting with processes in the System.Diagnostics.Process class (that I assume you are using to start this external application)

davisoa
  • 5,407
  • 1
  • 28
  • 34
  • Yes, the application i am starting exist after the dialog. The problem is that i need to do some more tasks on that application after the dialog is closed. – hs2d Oct 04 '11 at 14:06