Advertisement
Guest User

Profiling sample

a guest
Jun 20th, 2016
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ProfilingSpike
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             var task = new MyOperationAsync().GetTheAnswerAsync();
  15.             Task.WaitAll(task);
  16.         }
  17.     }
  18.  
  19.     public class MyOperationAsync
  20.     {
  21.         public async Task<int> GetTheAnswerAsync()
  22.         {
  23.             Console.WriteLine(Thread.CurrentThread.ManagedThreadId);
  24.             await Task.Delay(5000);
  25.             await DoSomethingElseAsync();
  26.             return 42;
  27.         }
  28.  
  29.         public async Task DoSomethingElseAsync()
  30.         {
  31.             Console.WriteLine(Thread.CurrentThread.ManagedThreadId);
  32.             await Task.Delay(2000);
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement