difference between Process.WaitForInputIdle and App.Sleep

Class library usage, coding and language questions.
nitin
Posts: 8
Joined: Thu Nov 09, 2006 5:56 am
Contact:

difference between Process.WaitForInputIdle and App.Sleep

Post by nitin » Wed Apr 15, 2009 12:08 pm

Hi All,

I am testing Visual Studio Addin, so my test open visual studio process and do some tests now problem is at the time of closing its take too much time
so, i have to wait till the process is properly exist

Added code like
==============================================
if (vsProcess.HasExited) return;
Application.Sleep(1000);
vsProcess.WaitForInputIdle(waitTimeMaxMsecsShutdown);
vsProcess.CloseMainWindow();
vsProcess.WaitForExit(waitTimeMaxMsecsShutdown);
Application.Sleep(2000);
int count = 0;
while (!vsProcess.HasExited && count < 5 )
{
this.SaveSolution();
Application.Sleep(200);
}
if (!vsProcess.HasExited)
{
vsProcess.Kill();
throw new Exception("Can not close Visual Studio -> Killed it");
}
==============================================

is it optimize way to check process exit or else kill it after few time.
Any good solution from Ranorex.

samething for opening visual studio as it take too much time so cant predict how much handle it.



Thanks and Regards,
Nitin

nitin
Posts: 8
Joined: Thu Nov 09, 2006 5:56 am
Contact:

difference between Process.WaitForInputIdle and App.Sleep

Post by nitin » Thu Apr 16, 2009 8:35 am

Hi All,

Waiting for reply.

Thanks and Regards,
Nitin

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Post by Support Team » Thu Apr 16, 2009 9:17 am

Hi Nitin,

To check whether your application is closed you can use the find method to search for it (e.g. by its title). If your app is closed the find method's return value will be null then.

The latest Ranorex 2.0 version gives you a better support for searching GUI elements with long loading times.

Kind regards,
Gabor
Ranorex Support Team

nitin
Posts: 8
Joined: Thu Nov 09, 2006 5:56 am
Contact:

difference between Process.WaitForInputIdle and App.Sleep

Post by nitin » Thu Apr 16, 2009 12:02 pm

Hi Gabor,

Thanks for reply,

Could you please tell me, what is meaning of below these API.

vsProcess is visual studio process
=======================
bool done = false;
Element statusBar = StatusBar;
while (!done && count < 20)
{
count++;
vsProcess.WaitForInputIdle(waitTimeMaxMsecs);
Application.Sleep(100);
if (statusBar != null && statusBar.Value.StartsWith(statusBarContent))
done = true;
}
=======================
Here i am trying to wait still visual studio is properly open in "Ready" Status within waitTimeMaxMsecs=10000 same loop 20 times.

Is these two APIs (WaitForInputIdle and Sleep) together required or only one can handle this. mean only one using WaitForInputIdle or Sleep function.

Thanks and Regards,
Nitin

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Post by Support Team » Thu Apr 16, 2009 4:38 pm

The Process.WaitForInputIdle method is a .NET Framework method, please consult the .NET Framework documentation:
http://msdn.microsoft.com/en-us/library/kcdbkyt4.aspx

The Ranorex.Application.Sleep method suspends the currently running thread for the specified number of milliseconds.

I can't answer your question whether you need both since this heavily depends on your application. In general, I would rather try to search for a control/element inside the application in a loop until you find the control/element. In Ranorex 2.0 this is done by default if you search for an element.

Regards,
Alex
Ranorex Support Team