Created
July 23, 2018 04:44
-
-
Save mojeld/577f184b71ff52ee8b5c18e282d0354b to your computer and use it in GitHub Desktop.
UWP - Task.Run()とDispatcher.RunAsync()を使ってasync/await
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
private async void Button_ClickAsync(object sender, RoutedEventArgs e) | |
{ | |
p1.IsEnabled = true; | |
p1.IsIndeterminate = true; | |
t1.Text = "5000数えた後時間表示"; | |
await Task.Run(async () => | |
{ | |
//何か重たい処理 | |
for (int i = 0; i < 5000; ++i) | |
{ | |
Debug.WriteLine("{0}", DateTime.Now); | |
} | |
// for のそこそこの処理が終わった後 | |
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () => { | |
t1.Text = string.Format("{0}", DateTime.Now); //テキストボックスに書く | |
p1.IsIndeterminate = false; //プログレスバーのアニメを止める | |
p1.IsEnabled = false; | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment