Answers for "how to await a task c#"

C#
-2

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();
}
Posted by: Guest on October-08-2020

C# Answers by Framework

Browse Popular Code Answers by Language