This is a migrated thread and some comments may be shown as answers.

Wait for one or the other element

0 Answers 48 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kris
Top achievements
Rank 1
Kris asked on 23 Jul 2012, 11:01 AM
To wait for an element to exist, you have to do this:

var element = app.FindName("element");
element.Wait.ForExists();

In my silverlight application, at some point I have to wait for either elementA to exist or elementB to exist. So I created two tasks that each wait for one of the elements to exist:

var waitForElementATask = Task.Factory.StartNew(() => WaitForElement("elementA"));
var waitForElementBTask = Task.Factory.StartNew(() => WaitForElement("elementB"));
Task.WaitAny(waitForElementATask ,waitForElementBTask);

with WaitForElement() being:

private void WaitForElement(string name)
{
   var element = app.FindName(name);
   element.Wait.ForExists();
}

I thought this would be a good way to find out which one of the two elements show up. However, when I run this code, neither element will ever be found, even though they do show up. 

Anybody has any ideas?
Tags
General Discussions
Asked by
Kris
Top achievements
Rank 1
Share this question
or