Warm tip: This article is reproduced from serverfault.com, please click

c#-显示字符串异步延迟

(c# - Display string async with delay)

发布于 2020-12-07 15:50:15

我尝试在网页中显示延迟的字符串,以下是我尝试的操作,但是直到延迟过期,该页面才显示。

protected void Page_Load(object sender, EventArgs e)
{
    Print().GetAwaiter().GetResult();
}

private async Task Print()
{
    await Task.Run(async () =>
    {
        await Task.Delay(10000);
        pr.InnerText = "this is a test...";
    });
}
Questioner
Tico
Viewed
11
terrencep 2020-12-07 23:53:44

我建议从后端删除此延迟,并在前端使用javascript异步调用字符串的后端。你可以使用setTimeout和ajax post完成此操作。