Page 1 of 1

Is it possible to wait for a runapplication to complete

Posted: Mon May 20, 2013 1:59 pm
by garyb576
I am trying to run a shell command within my test using runapplication. however, I also want to wait for that to complete before my scripts continue and carry on. Is there a way of doing this?
I can manually add a delay after using runapplication, however, I wanted the test to bit smarter than that and to wait til it completes.

Re: Is it possible to wait for a runapplication to complete

Posted: Mon May 20, 2013 3:02 pm
by odklizec
Hi,

Try for example Wait For Not Exists action. Set a reasonable timer based of your experience with the execution time of your shell script. If you set the timer too low, the next action will be started before the shell script is finished! Just "Wait" action right after the action where you start the shell command...
WaitForNotExists_1.png
Eventually, you can do something similar from code, using the process name and while loop with timeout...
WaitForNotExists_2.png
using System.Diagnostics;
        public void Wait_For_Not_Exist_code()
        {
        	int ElapsedTime = 0;
        	while (Process.GetProcessesByName("cmd").Length >= 1 && ElapsedTime < 300000)
        	{
        		Thread.Sleep(1000);
        		ElapsedTime += 1000;
        	}
        }
Hope this helps?

Re: Is it possible to wait for a runapplication to complete

Posted: Tue May 21, 2013 7:59 am
by garyb576
I have decided to use system.diagnostics and use the new process and within that use process.waitforexit etc
This seems to be working as expected.
Thanks for your suggestion.

Re: Is it possible to wait for a runapplication to complete

Posted: Tue May 21, 2013 9:11 am
by odklizec
You are welcome. And thanks for sharing your solution!