I want to enumerate files in a folder and then process each file. Normally I would have done this by creating a thread and updating the UI after each file was processed with the result.
Now I want to do this in an async and await style... I'm a bit stuck with code that looks a bit like this:
public async void ProcessActions()
await Task.Run(() => ProcessNextAction());
private async Task ProcessNextAction()
if (m_nCurrentAction >= m_Actions.Count)
m_bAllActionsProcessed = true;
return; // done.
Action<object> action = (object obj) =>
DirectoryAction directoryAction = m_Actions[m_nCurrentAction];
DirectoryInfo info = new DirectoryInfo(directoryAction.GetDirectory());
FileInfo files = info.GetFiles("*", directoryAction.GetRecurse() ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
foreach (FileInfo fileInfo in files)
// and now --> also, how do I run this task??