/// <summary> /// Waits appearance of the first folder in the collection data folder /// </summary> public static Task WaitStartCollectData(Logcfg logcfg) { var tcs = new TaskCompletionSource <bool>(); var logPaths = logcfg.GetLogPaths(); FileSystemWatcher[] watchers = new FileSystemWatcher[logPaths.Length]; for (int x = 0; x < logPaths.Length; x++) { var watcher = new FileSystemWatcher { NotifyFilter = NotifyFilters.DirectoryName, Path = logPaths[x], Filter = "*" }; watcher.Created += (sender, args) => { watchers.ToList().ForEach(c => c.EnableRaisingEvents = false); tcs.TrySetResult(true); watchers.ToList().ForEach(c => c.Dispose()); }; watchers[x] = watcher; } watchers.ToList().ForEach(c => c.EnableRaisingEvents = true); return(tcs.Task); }