ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

Storyboard.BeginAsync()

Begin an XAML Storyboard using the async/await pattern instead of using the completed event.

Source

public static Task BeginAsync(this Storyboard storyboard) {
    System.Threading.Tasks.TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
    if (storyboard == null)
        tcs.SetException(new ArgumentNullException());
    else {
        EventHandler<object> onComplete = null;
        onComplete = (s, e) => {
            storyboard.Completed -= onComplete;
            tcs.SetResult(true);
        };
        storyboard.Completed += onComplete;
        storyboard.Begin();
    }
    return tcs.Task;
}

Example

await StoryBoard1.BeginAsync();

Author: Fons Sonnemans

Submitted on: 25 okt. 2013

Language: C#

Type: Windows.UI.Xaml.Media.Animation.Storyboard

Views: 13055