//we use a static GetNew instead of a public constructor //as some things like waiting on async operations //and setting event handlers cannot be done in the //constructor. the real constructor is kept private //and only ever called from this static GetNew method public static async Task <FileMapBySize> GetNew( IDispatcher d, IDirectory dir, DuplicateFileFinder.FileReadError error, EventHandler onscanned) { var fileMapBySize = new FileMapBySize(d); fileMapBySize.OnFileReadError = error; fileMapBySize.OnFileScanned = onscanned; await fileMapBySize.Populate(dir); return(fileMapBySize); }
private void NotifyFileReadError(string path, Exception e) { DuplicateFileFinder.FileReadError onFileReadError = OnFileReadError; if (onFileReadError != null) { Action action = () => onFileReadError(path, e); if (dispatcher != null) { dispatcher.Execute(action); } else { action(); } } }