111,097
社区成员




Task.Run(async delegate
{
await Task.Delay(100); //延迟100毫秒,避免阻塞进程
try
{
//TODO: 自己的处理逻辑
}
catch (Exception exception)
{
//TODO: 异常处理
}
});
private static async Task<int> GetDiceRoll()
{
Console.WriteLine("...Shaking the dice...");
int roll1 = await Roll();
int roll2 = await Roll();
return roll1 + roll2;
}
private static async Task<int> Roll()
{
if (rnd == null)
rnd = new Random();
await Task.Delay(500);
int diceRoll = rnd.Next(1, 7);
return diceRoll;
}