【问题标题】:Process.StartInfo.RedirectStandardInput uses too much CPUProcess.StartInfo.RedirectStandardInput 使用过多 CPU
【发布时间】:2021-04-21 17:56:44
【问题描述】:

我创建了一个应用程序来打开 AutoCAD Core Console 以向其写入一些命令。问题是单个线程的空闲 CPU 使用率为 100%。我发现 RedirectStandardInput 属性在设置为 true 时会执行此操作。当我将其设置为 false 时,空闲 CPU 使用率为 0.1%。我需要的是能够向控制台写入命令,当一切都完成后,空闲速度恢复到 0.1% 的 CPU 使用率。为什么会发生这种情况,我该如何解决?

            // Set up process
            coreprocess.StartInfo.Arguments = "/isolate";
            coreprocess.StartInfo.UseShellExecute = false;
            coreprocess.StartInfo.CreateNoWindow = true;
            coreprocess.StartInfo.RedirectStandardOutput = false;
            coreprocess.StartInfo.RedirectStandardError = false;
            coreprocess.StartInfo.RedirectStandardInput = true;
            coreprocess.StartInfo.FileName = installpath;
            
            // Start Process
            this.ConsoleStarted = coreprocess.Start();

【问题讨论】:

    标签: c# .net process autocad


    【解决方案1】:

    我删除了以下代码部分,一切正常。

    coreprocess.StandardInput.Close();
    coreprocess.StandardInput.Dispose();
    

    【讨论】:

    • 提示:Dispose() 在任何类型的 Stream 上都会在内部关闭它,永远不需要在 Dispose() 之前显式调用 Close()。
    猜你喜欢
    • 2011-04-03
    • 2010-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多