I have a question for the Ranorex developers: What part of the Ranorex API is threadsafe?
The following examples work reliable in my tests in the positive and negative case and the time savings can be substantial, however the error messages are usually off and refer to the wrong item if I force a failure of one of the xpaths lookup Tasks.
Example 1 "WhenAny"
Let's say, we have either SphereA or SphereB present on page and both have potentially long load times. When either one appears, click on the one that appears and move on, don't wait for the other to time out.
Code: Select all
[...]
var tasks = new List<Task>();
tasks.Add(Task.Run(() => taskA()));
tasks.Add(Task.Run(() => taskB()));
Task t = Task.WhenAny(tasks);
[...]
Code: Select all
void taskA() {
if(r.WhenAny_html.SphereAInfo.Exists()) {r.WhenAny_html.SphereA.Click();}
}
void taskB() {
if(r.WhenAny_html.SphereBInfo.Exists()) {r.WhenAny_html.SphereB.Click();}
}
Validate a large number of items while considering that life is short and our processors have many cores and threads:
Code: Select all
[...]
var tasks = new List<Task>();
tasks.Add(Task.Run(() => Validate.Exists("/dom[@page='WhenAll.html']/body/input[@id='a1']",timeout)));
tasks.Add(Task.Run(() => Validate.Exists("/dom[@page='WhenAll.html']/body/input[@id='a2']",timeout)));
tasks.Add(Task.Run(() => Validate.Exists("/dom[@page='WhenAll.html']/body/input[@id='a3']",timeout)));
Task t = Task.WhenAny(tasks);
[...]
Uwe Schmidt