c# await task to complete code example
Example: how to await a task c#
private async void myEvent()
{
Task myTask = MyFunction(); // MyFunction should return a task!
var result = await myTask;
}
private void SomeFunction()
{
// some code
// .....;
//
myEvent?.Invoke(); // Invoke myEvent -> myEvent is async
Task.WaitAny(myTask);
if(myTask.isCompleted)
DoSomething();
}