public void TestKillProcess() { string path = "C:\\SoftwareMiner\\CryptoDredge_0.9.3\\start-BCD-bcd-zpool.bat"; Process _runningMinerProcess; var startInfo = new ProcessStartInfo(); startInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(path); startInfo.CreateNoWindow = false; startInfo.UseShellExecute = true; // startInfo.RedirectStandardOutput = false; startInfo.FileName = path; _runningMinerProcess = System.Diagnostics.Process.Start(startInfo); string message = DateTime.Now.ToString("yyyy-MM-dd HH':'mm") + " start " + path; EasyLog.Log(@"c:\\Log\\minerlog.txt", message); System.Threading.Thread.Sleep(10000); if (_runningMinerProcess != null) { MinerControl.KillProcessAndChildrens(_runningMinerProcess.Id); message = DateTime.Now.ToString("yyyy-MM-dd HH':'mm") + " stop " + _runningMinerProcess.StartInfo.FileName; EasyLog.Log(@"c:\\Log\\minerlog.txt", message); _runningMinerProcess = null; } Assert.AreEqual(null, _runningMinerProcess); }
private static void CloseExistsMiner() { if (_runningMinerProcess != null) { KillProcessAndChildrens(_runningMinerProcess.Id); string message = DateTime.Now.ToString("yyyy-MM-dd HH':'mm") + " stop " + _runningMinerProcess.StartInfo.FileName; EasyLog.Log("minerlog.txt", message); _runningMinerProcess = null; } }
private static void RunMiner(string path) { try { var startInfo = new ProcessStartInfo(); startInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(path); startInfo.CreateNoWindow = false; startInfo.UseShellExecute = true; // startInfo.RedirectStandardOutput = false; startInfo.FileName = path; _runningMinerProcess = System.Diagnostics.Process.Start(startInfo); string message = DateTime.Now.ToString("yyyy-MM-dd HH':'mm") + " start " + path; EasyLog.Log("minerlog.txt", message); } catch (Exception err) { throw new Exception("Please verify the configuration file [miner.json] or your .bat file has invalid config.", err); } }