I have a snippet that looks like this,
private void btn_Click(object sender, EventArgs e)
{
try
{
var res = Task.Run(() => DoTask(param1, param2));
if(res.IsCompleted)
{
MessageBox.Show("Done");
}
MessageBox.Show("DoTask isn't called yet.");
}
catch
{
MessageBox.Show("Something wrong");
}
}
The DoTask
method looks like this
private async Task<bool> DoTask(int p1, int p2)
{
// run long tasks
}
I'd want to show Done
message after the task is done. But this never works. Instead the message DoTask isn't called yet.
is always called before DoTask
does tasks.