Better Way to "Wait"? RRS feed

  • Question

  • I have 2 media elements on top of one another to run a slide show. One fades the picture in, the other fades the picture out making a kind of fade transition between the two. I was running into a problem where there was a blink in the in the transition because it was taking a moment for the new picture to load so the two fades were out of sync, so to speak.

    I created this:

        Async Function WaitPic() As Task
            Await Task.Delay(2000)
        End Function

    And called it right after loading the new picture:

            PicIn.Source = New Uri(Me.LstSlideShow1.SelectedItem)
            Await WaitPic() 'a delay to wait for the picture to load, otherwise there's a blink in the fading of the two

    This is working on a couple of different computers but I'm guessing I could potentially have the same problem if there is any kind of delay in loading the picture, so I'm looking for a better way.

    Is there a way to wait for the loading of the picture or for the completion of a DoubleAnimation?

    Thank you,

    Monday, December 24, 2018 4:59 AM

All replies

  • Maybe you should set the Source properties, than start the transition when both of the media elements received the MediaOpened event. The controls can be initially invisible.

    • Edited by Viorel_MVP Monday, December 24, 2018 5:55 AM
    Monday, December 24, 2018 5:52 AM
  • Hi,

    Is it a WPF project  or a Winform project?

    Best Regards,


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Monday, December 24, 2018 9:53 AM
  • Sorry, Alex, WPF.

    Hmmm, hadn't noticed the media opened event. Maybe I could use that to set a flag and simply loop watching for the flag to set after setting the source? Might just work!

    I'll check it out.

    Thanks very much!

    Monday, December 24, 2018 1:36 PM