SHARE
TWEET

Untitled

a guest May 19th, 2019 56 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.Tasks;
  6. using System.Threading;
  7. using System.Diagnostics;
  8.  
  9. namespace _16052019___Listen
  10. {
  11.     class Program
  12.     {
  13.         public CancellationTokenSource cts = new CancellationTokenSource();
  14.  
  15.         static void Main(string[] args)
  16.         {
  17.             //List<int> myList = new List<int>() { 2, 7, 3, 1, 7, 3, 9, 10 };
  18.             //List<string> myList2 = new List<string>() { "\r\n" ,"Mateusz", "Matze", "Tatze", "Katze" };
  19.             //foreach(int a in myList)
  20.             //{
  21.             //    Console.WriteLine(a);
  22.             //}
  23.  
  24.             //foreach(string b in myList2)
  25.             //{
  26.             //    Console.WriteLine(b);
  27.             //}
  28.             //for (int i = 0; i < myList.Count; i++)
  29.             //{
  30.             //    Console.WriteLine("\r\n" + myList[i] + "\r\n");
  31.             //}
  32.             //Console.ReadKey();
  33.             CancellationToken ct = cts.Token;
  34.             Stopwatch sp = new Stopwatch();
  35.             sp.Start();
  36.             var a =  Methode();
  37.             var b = berechneNamen();
  38.             Console.WriteLine("Ich hei├če " + berechneNamen().Result + " und ich bin "+ Methode().Result + " Jahre alt.");
  39.             sp.Stop();
  40.             Console.WriteLine(sp.Elapsed);
  41.             Console.ReadKey();
  42.         }
  43.         public static async Task<int> Methode()
  44.         {
  45.             await Task.Delay(2000);
  46.             Task<int> t = Task.Run(() =>
  47.             {
  48.                 return 18;
  49.             });
  50.             await t;
  51.             return t.Result;
  52.         }
  53.         public static async Task<string> berechneNamen()
  54.         {
  55.             await Task.Delay(1000);
  56.             Task<string> t2 = Task.Run(() =>
  57.             {
  58.                 var vname = "Mateusz ";
  59.                 var nname = "Wojtasik";
  60.                 return vname + nname;
  61.             });
  62.             await t2;
  63.             return t2.Result;
  64.         }
  65.     }
  66. }
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
 
Top