For example, I have already written some asynchronous function and want to call it on button click. Like this:
static async Task<string> ParseSth(string URL) { ... }
And I want to call it when I click this button:
FindViewById<Button>(Resource.Id.ButtonParse).Click += ...
In google or youtube I found material only about lamda expressions. So, how to do this?
You can make your click handler async and then call ParseSth from there with an await. Just know that any exception thrown by your method won’t’ be caught because you’re adding async to a void method.
private async void button_Click(object sender, EventArgs e)
{
await ParseSth(myTextBox.Text); // Any exception thrown here will be lost
}
Another solution with some MVVM frameworks could be to bind an async command to your button click.