Wait for one or the other element

1 posts, 0 answers
  1. Kris
    Kris avatar
    1 posts
    Member since:
    Jul 2012

    Posted 23 Jul 2012 Link to this post

    To wait for an element to exist, you have to do this:

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

    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);

    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?
Back to Top