2016년 8월 30일 화요일

c# asnyc await example Simple notation



private void button1_Click(object sender, EventArgs e)
{
Console.WriteLine("in ");
method1();

//Thread.Sleep(1000);
Console.WriteLine( "out");

}

async void method1()
{
Console.WriteLine("in method1");
await Task.Run(() => awmethod() );
Console.WriteLine("out method1");
}

void awmethod()
{
Thread.Sleep(3000);
Console.WriteLine("Here Here");
}

----------------------




private void button1_Click(object sender, EventArgs e)
{
Console.WriteLine("in ");
method1();

//Thread.Sleep(1000);
Console.WriteLine( "out");

}

async void method1()
{
Console.WriteLine("in method1");
await getmethod();
Console.WriteLine("out method1");
}

void awmethod()
{
Thread.Sleep(3000);
Console.WriteLine("Here Here");
}

Task getmethod()
{
Task task = Task.Run(() => awmethod());
return task;
}

----------------------



private void button1_Click(object sender, EventArgs e)
{
Console.WriteLine("in ");
method1();

//Thread.Sleep(1000);
Console.WriteLine( "out");

}

async void method1()
{
Console.WriteLine("in method1");
await getmethod();
Console.WriteLine("out method1");
}

void awmethod()
{
Thread.Sleep(3000);
Console.WriteLine("Here Here");
}

Task getmethod()
{
Task task = new Task(() => awmethod());
task.Start();

return task;
}

댓글 없음:

댓글 쓰기