Delayed function calls

后端 未结 12 1298
星月不相逢
星月不相逢 2020-11-30 22:07

Is there a nice simple method of delaying a function call whilst letting the thread continue executing?

e.g.

public void foo()
{
    // Do stuff!

           


        
12条回答
  •  -上瘾入骨i
    2020-11-30 22:33

    Thanks to modern C# 5/6 :)

    public void foo()
    {
        Task.Delay(1000).ContinueWith(t=> bar());
    }
    
    public void bar()
    {
        // do stuff
    }
    

提交回复
热议问题