Here is my overridden method (which capture every pressed button on the keyboard on my form):
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (btnTarget.Focused && keyData == Keys.Enter)
{
// doing something in another thread and waiting for its result (async awaiting)
if (result)
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
But I do not know how to make it async-await
. I tried to use Task.Run
or SynchronizationContext.Current.Post
or other tricks to make a clean async-await
which waits for user interaction and then continue the rest.
So how to solve this issue in a clean way?