using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace HelloWorld
{
public class App
{
//생성자
public App()
{
Action action2 = () => { };
Task t1 = new Task(action2);
//Action<object> action = (obj) => { };
Action<object> action = MyAction;
// 매개변수 obj
Task t2 = new Task(action, "alpha");
Task t3 = Task.Factory.StartNew(action, "beta");
t3.Wait();
t2.Start();
Console.WriteLine("Hello Wrold!");
string obj = "delta";
Task t4 = Task.Run(() => {
Console.WriteLine("{0}, {1}", Thread.CurrentThread.ManagedThreadId, obj);
});
t4.Wait();
}
void MyAction(object obj)
{
Console.WriteLine("{0}, {1}", Thread.CurrentThread.ManagedThreadId, obj);
}
}
}
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace HelloWorld
{
public class App
{
//생성자
public App()
{
//반환값부터 작성하고 값에 맞게 <Type>작성
//Task<int> task = Task<int>.Run(() =>
//{
// return 100;
//});
Task<int> task = Task<int>.Factory.StartNew(() =>
{
return 100;
});
Console.WriteLine("result: {0}", task.Result);
}
}
}