SHARE
TWEET

Profiling sample

a guest Jun 20th, 2016 124 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top