Advertisement
express-rus

Task and Async Test

Apr 5th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | None | 0 0
  1. //1 ------------ Universal apps --------
  2. private async void but1_Click(object sender, RoutedEventArgs e)
  3.         {
  4.             ProgressUpdateTop.Visibility = Visibility.Visible;
  5.             await getMethod("all");
  6.             ProgressUpdateTop.Visibility = Visibility.Collapsed;
  7.         }
  8.  
  9.         private async Task getMethod(string p)
  10.         {
  11.             string test = p + "!!";
  12.             await Task.Delay(5000);
  13.             test += p;
  14.             MessageDialog msgbox = new MessageDialog("Message Box is displayed");
  15.             await msgbox.ShowAsync();  
  16.         }
  17.  
  18. //2 ------------ WPF desktop apps --------
  19. private async void but1_Click(object sender, RoutedEventArgs e)
  20.         {
  21.             ProgressUpdateTop.Visibility = Visibility.Visible;
  22.             await getMethod("all");
  23.            
  24.             ProgressUpdateTop.Visibility = Visibility.Collapsed;
  25.         }
  26.  
  27.         private async Task getMethod(string p)
  28.         {
  29.             string test = p + "!!";
  30.             await Task.Delay(5000);
  31.             test += p;
  32.             MessageBox.Show("Message Box is displayed");
  33.            
  34.             await Task.Run(async () =>
  35.             {
  36.                 Thread.Sleep(5000);
  37.                 //await this.Dispatcher.InvokeAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => getMethod("all"));
  38.             });
  39.             MessageBox.Show("Message Box is displayed2");
  40.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement