Calling an async method from a synchronous method

前端 未结 3 985
忘掉有多难
忘掉有多难 2020-12-09 18:47

I am attempting to run async methods from a synchronous method. But I can\'t await the async method since I am in a synchronous method. I must not be und

3条回答
  •  孤城傲影
    2020-12-09 19:06

    Task.Result (or Task.Wait() when there's no result) is similar to await, but is a synchronous operation. You should change GetData1() to use this. Here's the portion to change:

    Task dataTask = Task.WhenAny(runningTasks).Result;
    runningTasks.Remove(dataTask);
    myData = gameTask.Result;
    

提交回复
热议问题