我使用Robocopy将文件从一台计算机移动到另一台计算机。我使用的代码如下:
public void MoveRecords()
{
try
{
using (Process Robocopy = new Process())
{
Robocopy.StartInfo.FileName = this._commandPromptCommand;
Robocopy.StartInfo.Arguments = this._commandPromptString;
Robocopy.StartInfo.UseShellExecute = false;
Robocopy.StartInfo.CreateNoWindow = true;
Robocopy.Start();
DateTime StartTime = DateTime.Now;
if (Robocopy.WaitForExit(AppSettings.MaxMoveOperationWaitTime))
{
TimeSpan ElapsedTime = DateTime.Now - StartTime;
this._logRobocopyExitCode(Robocopy.ExitCode, ElapsedTime);
}
else
{
Logger.Write(string.Format("Timeout occured for the move operation of {0} from {1}. ", _getFilesInProgress(), this._ip), EventLogEntryType.Error);
Robocopy.Kill();
}
}
}
catch (Exception ex)
{
Logger.Write(ex, EventLogEntryType.Error);
}
}当我查看任务管理器时,我看到了许多“控制台窗口主机”和"Microsoft Robocopy“进程。你可以从下面的截图中看到这种情况。

我该如何解决这个问题?
发布于 2013-06-06 05:29:04
也许你需要一个"process.close“。下面是我在VB.NET中使用的一个示例:
' Create an instance of the command prompt and run RoboCopy for the current network location.
Try
pCmdPrompt = New Process
With pCmdPrompt
.StartInfo.FileName = Environment.SystemDirectory & "\RoboCopy.exe" ' Resides in System32
.StartInfo.Arguments = strDirSrc & " " & strDirDest & strRoboCopyArg & strLogFileFullName
End With
pCmdPrompt.Start() ' Begin RoboCopy
pCmdPrompt.WaitForExit() ' Wait for RoboCopy to complete. Needed in order to obtain DateEnd for Duration details for log.
pCmdPrompt.Close() ' RoboCopy completed. Close.
pCmdPrompt = Nothing ' Clean up for next loop.
' RoboCopy occurred w/o exception. Set string that will be used for log entry.
strDetailsDone = "Success"
Catch ex As Exception
' Exception occurred during RoboCopy. Set string that will be used for log entry.
' Continue w/ processing - do NOT halt application.
strDetailsDone = "Exception occurred: " & ex.Message & vbCrLf & ex.StackTrace
If pCmdPrompt IsNot Nothing Then pCmdPrompt = Nothing
End Tryhttps://stackoverflow.com/questions/16916759
复制相似问题