What's the best implemention for non-blocking wait/delay for a period of time in c#

前端 未结 1 704
北海茫月
北海茫月 2021-01-25 06:04

Currently I need to implement a simple non-blocking delay function in a Windows Store app project. This function should do nothing, just idle for a specific period of time witho

相关标签:
1条回答
  • 2021-01-25 06:43

    See Task.Delay

    It schedules a task that completes at a future time using timer rather than blocking a thread.

    An example that waits 5 seconds and then continues:

    private async Task DelayThenDoSomeWork()
    {
        await Task.Delay(5000);
        // Do something
        var dialog = new MessageDialog("Waiting completed.");
        await dialog.ShowAsync();
    }
    
    0 讨论(0)
提交回复
热议问题