代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Runtime.CompilerServices;
namespace ConsoleApp7
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("hello word");
TaskAwaiter<string> taw = getStrAsync().GetAwaiter();
taw.OnCompleted(OnCompleteAwaiter);
void OnCompleteAwaiter()
{
Console.WriteLine(taw.GetResult());
}
Console.ReadKey();
}
static string getStr() {
return "str";
}
static Task<string> getStrAsync() {
var t1 = new Task<string>(getStr);
t1.Start();
return t1;
}
}
}
运行结果