-
-
Save SriramSakthivel/2488faffc44bd99eb79c to your computer and use it in GitHub Desktop.
Extension method to await ShowDialog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
using System.Windows; | |
namespace AsyncShowDialog | |
{ | |
public static class AsyncWindowExtension | |
{ | |
public static Task<bool?> ShowDialogAsync(this Window self) | |
{ | |
if (self == null) throw new ArgumentNullException("self"); | |
TaskCompletionSource<bool?> completion = new TaskCompletionSource<bool?>(); | |
self.Dispatcher.BeginInvoke(new Action(() => completion.SetResult(self.ShowDialog()))); | |
return completion.Task; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment