var timeouttask = Task.Delay(3000); //设置超时时间 var completedTask = await Task.WhenAny(new Task(async () => { await Task.Delay(4000);//执行的方法示例这里用延迟代替 }), timeouttask); if (completedTask == timeouttask) { }
var timeouttask = Task.Delay(3000); //设置超时时间 var completedTask = await Task.WhenAny(new Task(async () => { await Task.Delay(4000);//执行的方法示例这里用延迟代替 }), timeouttask); if (completedTask == timeouttask) { }
转载于:https://www.cnblogs.com/romanticcrystal/p/11083996.html