111,094
社区成员




Public async void Run (){
var rst=await xxx();
var rst2=xxx();
}
static void Main(string[] args)
{
Test();
Console.ReadKey();
}
public static async Task Test()
{
Task t = T1();
await T2();
await t;
}
public static async Task T1()
{
Console.WriteLine("T1 begin");
await Task.Delay(3000);
Console.WriteLine("T1 end");
}
public static async Task T2()
{
Console.WriteLine("T2 begin");
await Task.Delay(2000);
Console.WriteLine("T2 end");
}
Console.WriteLine("1" );
await PrintAsync();
Console.WriteLine("3" );
public static void PrintAsync()
{
Console.WriteLine("2 ");
}
和
Console.WriteLine("1" );
await PrintAsync();
Console.WriteLine("3" );
public static void PrintAsync()
{
Task tk1 = Task.Run(() =>
{
Thread.Sleep(5000);
Console.WriteLine("2 ");
});
}
看下结果
public async Task<bool> ExcuteSql() {
//执行插入数据
return true;
}
public bool ExcuteSql_2() {
//执行插入数据
return true;
}
public async void InsertData() {
var rst = await ExcuteSql();
var rst2 = ExcuteSql_2();
}