anonyme methode in ConsoleTask

This commit is contained in:
test 2019-05-03 15:44:56 +02:00
parent e00f16b679
commit 782a6da74e

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -11,21 +12,38 @@ namespace ConsoleAppTasks
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
//var t = new Task(DoIt);
var t = new Task(DoIt);
int i = 4;
int y = 0;
//anonyme methode
var t = new Task(() =>
{
Thread.Sleep(2000);
Console.WriteLine("2");
y = 2 * i;
});
t.Start(); t.Start();
i = 99;
t.Wait();
Console.WriteLine(y); //198
/*
for (int i = 0; i < 999; i++) for (int i = 0; i < 999; i++)
{ {
Console.WriteLine("-"); Console.WriteLine("-");
Thread.Sleep(200); Thread.Sleep(200);
} }
*/
Console.ReadLine(); //wait for close Console.ReadLine(); //wait for close
} }
@ -37,10 +55,7 @@ namespace ConsoleAppTasks
{ {
Console.WriteLine("+"); Console.WriteLine("+");
Thread.Sleep(500); Thread.Sleep(500);
}
} }
}
} }
} }