Dynamic wait

Ask general questions here.
rsudhak
Posts: 118
Joined: Fri Jan 04, 2019 1:38 pm

Dynamic wait

Post by rsudhak » Mon May 25, 2020 1:59 pm

HI I have created some dynamic wait methods.... but doesn't seem to work properly , any idea ?

// This one is related to mouse load
public static void WaitForMouseLoad(int maxLoopDuration)
{
string currentState = Mouse.Cursor.ToString();
System.DateTime start = System.DateTime.Now;

while ((currentState == "[Cursor: Default]" || currentState == "[Cursor: WaitCursor]") && System.DateTime.Now.Subtract(start).TotalMilliseconds < MAX_WAIT_TIME)
{
Thread.Sleep(500);
currentState = Mouse.Cursor.ToString();
}

if(System.DateTime.Now.Subtract(start).TotalMilliseconds > MAX_WAIT_TIME)
{
Ranorex.Report.Error("Application still reports busy state after exceeding the allotted time");
}
}


// this one is related to process being idle
public static void WaitForProcessIdle()
{
var perfCounter = new PerformanceCounter("Process", "% Processor Time", "Revit",true);
System.DateTime start = System.DateTime.Now;

perfCounter.NextValue();

float cpu = perfCounter.NextValue()/Environment.ProcessorCount;
Report.Info(cpu.ToString());
while (cpu > 0 && System.DateTime.Now.Subtract(start).TotalMilliseconds < MAX_WAIT_TIME)
{

Thread.Sleep(500);
cpu = perfCounter.NextValue()/Environment.ProcessorCount;
}

if(System.DateTime.Now.Subtract(start).TotalMilliseconds > MAX_WAIT_TIME)
{
Report.Failure("Application still reports busy state after exceeding the allotted time");
}
}

Any help on this would be great

Thanks,
Rajee

rsudhak
Posts: 118
Joined: Fri Jan 04, 2019 1:38 pm

Re: Dynamic wait

Post by rsudhak » Wed May 27, 2020 3:39 pm

Any thoughts on this please