Reputation: 1395
In an UWP app, I can get the MessageDialog to open when I use in a button click event like the code below:
private async void TestBtn_Click(object sender, RoutedEventArgs e)
{
// Create a MessageDialog
var dialog = new MessageDialog("This is my content", "Title");
// If you want to add custom buttons
dialog.Commands.Add(new UICommand("Click me!", delegate (IUICommand command)
{
// Your command action here
}));
// Show dialog and save result
var result = await dialog.ShowAsync();
}
But when I try to call the same event handler in a for loop, I see nothing in my app.
for (int i = 0; i < 10; i++)
{
TestBtn_Click(null, null);
}
I want the app to pause, and display some data like the Console.ReadLine() does.
Upvotes: 0
Views: 398
Reputation: 1882
Change your return type from void to Task which will make the message dialog to await.
// your function
private async Task TestBtn_Click(object sender, RoutedEventArgs e)
// where you call
for (int i = 0; i < 10; i++)
{
await TestBtn_Click(null, null);
}
Upvotes: 1