代码
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");
main2();
Console.ReadKey();
}
static async void main2() {
string r = await getStrAsync();
Console.WriteLine(r);
}
static string getStr() {
return "str";
}
static Task<string> getStrAsync() {
var t1 = new Task<string>(getStr);
t1.Start();
return t1;
}
}
}
运行结果