public static void GetFiles(this DirectoryInfo di, string searchPattern, FileFoundDelegate callback, string groupName) { BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += (sv, ev) => { // ProcessStartInfo processInfo; // Process process = new Process(); // processInfo = new ProcessStartInfo("cmd.exe");//, "/c dir " + di.FullName.TrimEnd('\\') + "\\*.sln /S /B"); // processInfo.CreateNoWindow = false; // processInfo.UseShellExecute = false; // processInfo.RedirectStandardOutput = true; // processInfo.RedirectStandardError = true; // processInfo.RedirectStandardInput = true; // process.StartInfo = processInfo; // process.Start(); //// string data = process.StandardOutput.ReadToEnd(); // process.EnableRaisingEvents = true; // process.BeginOutputReadLine(); // process.OutputDataReceived += (svv, evv) => // { // }; // process.StandardInput.WriteLine("dir " + di.FullName.TrimEnd('\\') + "\\*.sln /S /B"); // process.WaitForExit(); // process.Close(); ProcessStartInfo startInfo = new ProcessStartInfo(@"cmd.exe"); startInfo.CreateNoWindow = true; startInfo.ErrorDialog = false; startInfo.RedirectStandardError = true; startInfo.RedirectStandardInput = true; startInfo.RedirectStandardOutput = true; startInfo.UseShellExecute = false; startInfo.CreateNoWindow = true; Process process = new Process(); process.StartInfo = startInfo; process.Start(); Read(process.StandardOutput, callback, groupName); //Read(process.StandardError); process.StandardInput.WriteLine("dir " + di.FullName.TrimEnd('\\') + "\\*.sln /S /B"); process.WaitForExit(); string e = string.Empty; }; bw.RunWorkerAsync(); }
private static void Read(StreamReader reader, FileFoundDelegate callback, string groupName) { new System.Threading.Thread(() => { StringBuilder currentString = new StringBuilder(); while (true) { int current; while ((current = reader.Read()) >= 0) { currentString.Append((char)current); //Console.Write((char)current); if ((char)current == '\n') { if (File.Exists(currentString.ToString().Trim())) { FileInfo fi = new FileInfo(currentString.ToString().Trim()); DataManager.AddToCache(fi, groupName); callback(fi); } currentString = new StringBuilder(); } } } }).Start(); }