First off; don't use an async delegate here. You're needlessly complicating your code.
When you have an operation that is already asynchronous that you want to get the result of, await
it. If you have CPU bound work that you have to do then run just that in a Task.Run
call and await
it to get the result.
private void button1_Click(object sender, EventArgs e)
{
string data = await DownloadAsync();
button1.Text = await Task.Run(() => Compute(data));
}
Here it's very clear what's going on. Get the result of the asynchronous operation, use it to do some CPU bound work in a non-UI thread, then use that result in the UI context.
Now, having said all of that, I'd expect your code to actually work just fine as it is (given that the current context is not the UI context all throughout the Task.Run
delegate), but it's a lot harder to understand that code or see what it's doing.