Wait for image changed

Ask general questions here.
Ahmad
Posts: 17
Joined: Tue Apr 09, 2019 7:29 am
Location: Berlin

Wait for image changed

Post by Ahmad » Wed May 22, 2019 12:06 pm

Hi All,

I want to wait until the image in a container is changed. How can I do it?

I tried this Code, it works but I want to use time out for waiting.

Code: Select all

bool imageIsChanged = false;

While(imageIsChanged == false)
{
	if (Ranorex.Imaging.Contains(element, image) == false )
	{
		imageIsChanged = true;
	}
}
Thank you in advance for your support.

McTurtle
Posts: 255
Joined: Thu Feb 23, 2017 10:37 am
Location: Benedikt, Slovenia

Re: Wait for image changed

Post by McTurtle » Wed May 22, 2019 3:11 pm

Hi Ahmad,

You could use a stopwatch :)
public void WaitForImage()
		{
			bool imageIsChanged = false;
			int timeout=10000;
			
			Stopwatch t=new Stopwatch();
			t.Start();
			
			while(imageIsChanged == false && t.ElapsedMilliseconds<timeout)
			{	
				Report.Info(string.Format("Checking image on time {0} in ms.",t.ElapsedMilliseconds.ToString()));
				if (element, image) == false )
				{
					imageIsChanged = true;
				}
			}
			t.Stop();
		}
This will check at the start of the while-loop if you are already over the timeout. The timeout is set in ms. You need to not forget to add the namespace that contains the stopwatch:
using System.Diagnostics;
Regards,
McTurtle

Ahmad
Posts: 17
Joined: Tue Apr 09, 2019 7:29 am
Location: Berlin

Re: Wait for image changed

Post by Ahmad » Wed May 22, 2019 4:45 pm

it works.
Thank you very much :)