Sipo
0
Q:

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();
}
0

New to Communities?

Join the community