Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Threading;
- using System.Diagnostics;
- namespace _16052019___Listen
- {
- class Program
- {
- public CancellationTokenSource cts = new CancellationTokenSource();
- static void Main(string[] args)
- {
- //List<int> myList = new List<int>() { 2, 7, 3, 1, 7, 3, 9, 10 };
- //List<string> myList2 = new List<string>() { "\r\n" ,"Mateusz", "Matze", "Tatze", "Katze" };
- //foreach(int a in myList)
- //{
- // Console.WriteLine(a);
- //}
- //foreach(string b in myList2)
- //{
- // Console.WriteLine(b);
- //}
- //for (int i = 0; i < myList.Count; i++)
- //{
- // Console.WriteLine("\r\n" + myList[i] + "\r\n");
- //}
- //Console.ReadKey();
- CancellationToken ct = cts.Token;
- Stopwatch sp = new Stopwatch();
- sp.Start();
- var a = Methode();
- var b = berechneNamen();
- Console.WriteLine("Ich heiße " + berechneNamen().Result + " und ich bin "+ Methode().Result + " Jahre alt.");
- sp.Stop();
- Console.WriteLine(sp.Elapsed);
- Console.ReadKey();
- }
- public static async Task<int> Methode()
- {
- await Task.Delay(2000);
- Task<int> t = Task.Run(() =>
- {
- return 18;
- });
- await t;
- return t.Result;
- }
- public static async Task<string> berechneNamen()
- {
- await Task.Delay(1000);
- Task<string> t2 = Task.Run(() =>
- {
- var vname = "Mateusz ";
- var nname = "Wojtasik";
- return vname + nname;
- });
- await t2;
- return t2.Result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement