I've been looking for any simple example building async interfaces using ASP.NET WebForms. That is when an async
method is done the await
shall render.
This is one of the examples I've been looking at, How and When to use `async` and `await`. The implementation I've been looking for would look something like this
protected async void button1_Click(object sender, EventArgs e)
{
// Render when done
textBox1.Text += await WaitAsynchronouslyAsync(RandomNumber(2000, 4000));
// Render when done
textBox1.Text += await WaitAsynchronouslyAsync(RandomNumber(100, 1000));
}
public async Task<string> WaitAsynchronouslyAsync(int delay)
{
await Task.Delay(delay);
return string.Concat(delay, "; ");
}
private int RandomNumber(int min, int max)
{
Random random = new Random();
return random.Next(min, max);
}
This will however always render when everything is done, but at the same time. In the example above the desired result would be the second call to WaitAsynchronouslyAsync
to render before the first call since it always will be less delay.
Or is it even possible using webforms? I do know how to do this in JavaScript using webapi's, websockets and whatnot and that's not the solution I desire at the moment.