首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >进程(robocopy)未关闭

进程(robocopy)未关闭
EN

Stack Overflow用户
提问于 2013-06-04 19:34:33
回答 1查看 2K关注 0票数 1

我使用Robocopy将文件从一台计算机移动到另一台计算机。我使用的代码如下:

代码语言:javascript
复制
    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“进程。你可以从下面的截图中看到这种情况。

我该如何解决这个问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-06 05:29:04

也许你需要一个"process.close“。下面是我在VB.NET中使用的一个示例:

代码语言:javascript
复制
            ' 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 Try
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16916759

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档