I have the following asynchronous code:
public async Task<List<PreprocessingTaskResult>> Preprocess(Action onPreprocessingTaskFinished)
{
var preprocessingTasks = BuildPreprocessingTasks();
var preprocessingTaskResults = new List<PreprocessingTaskResult>();
while (preprocessingTasks.Count > 0)
{
//Wait till at least one task is completed
await TaskEx.WhenAny(preprocessingTasks.ToArray());
onPreprocessingTaskFinished();
}
return
}
And the asynchronous usage code
var preprocessingTaskResults = await Preprocess(someAction);
For some cases I need to call it in synchronous way. For simpler cases (when async method returns just a task) I used to do the following:
var someTask = AsyncMethod();
Task.Wait(someTask);
But I am confused how I should implement it here.