i'm currently upgrading some existing code for use by windows universal and am struggling to convert a command pattern to work with the new async/await functionality.
I have a command scheduler class that runs within its own thread and processes commands that have been added to its queue. The method in question looks like this:
private List<ICommandItem> _items;
private void ProcessCommands()
{
while(_items.count > 0)
{
_items[0].Execute();
_items.RemoveAt(0);
}
}
My problem is that some of my ICommandItem.Execute() methods now need to be async because they involve file io whilst others have no async methods. How could I modify the above pattern so that:
- my executor can handle both async and non-async ICommandItems
- The executor only starts execution of a command once the previous command has completed.
I would be happy to just execute the methods synchronously but that now causes deadlocks everywhere.