Wait for n seconds, then next line of code without freezing form

前端 未结 4 1536
长发绾君心
长发绾君心 2020-12-15 20:45

Hi I am trying to find a method of waiting a number of milliseconds before moving to the next line of code,

I have looked into Thread.Sleep but this will freeze the

4条回答
  •  天命终不由人
    2020-12-15 21:13

    The await keyword, in conjunction with Task.Delay makes this trivial.

    public async Task Foo()
    {
        await Task.Delay(2000);
        txtConsole.AppendText("Waiting...");
        DoStuff();
    }
    

提交回复
热议问题