草庐IT

DETACH_PROCESS

全部标签

c# - Process.Start() 比在控制台中执行慢得多

我在使用Process.Start()执行.exe时遇到性能问题。.NET的执行时间大约是控制台的5倍。什么会导致这个?这是一个测试程序:publicstaticvoidMain(string[]argv){for(inti=0;i结果是这样的:0Elapsedtime4310ms.1Elapsedtime4330ms.2Elapsedtime4280ms....在cmd窗口中运行它几乎立即返回(不到1秒的执行时间)。尝试使用在控制台中对其进行计时>powershellMeasure-Command{cmd/cstart/wait%EXE%%ARGS%}执行时间大约为750毫秒,快了5

c# - 如何在没有 "process has exited"异常的情况下终止进程?

我使用Process.Kill()来终止进程。像这样:if(!process.WaitForExit(5000)){process.Kill();}有时进程会在两行之间退出,所以控制会进入if然后Kill会产生异常:System.InvalidOperationExceptionCannotprocessrequestbecausetheprocess(ProcessIdHere)hasexited.atSystem.Diagnostics.Process.GetProcessHandle(Int32access,BooleanthrowIfExited)atSystem.Diagno

c# - Process.Start() 从命令提示符窗口获取错误

我正在尝试使用参数启动命令提示进程。现在我想获取有关错误的信息(如果存在)。someProcess=System.Diagnostics.Process.Start(cmd,someArgs);最好的问候,洛维吉 最佳答案 其他答案都是正确的。这是您可以使用的一些代码:ProcessStartInfostartInfo=newProcessStartInfo(cmd,args);startInfo.UseShellExecute=false;startInfo.RedirectStandardError=true;Processso

c# - Process.Start() 和 PATH 环境变量

我有以下简单的C#应用程序,它只是尝试启动“jconsole.exe”,它在我的机器上位于C:\Programs\jdk16\bin中。usingSystem;usingSystem.Diagnostics;namespacednet{publicclassdnet{staticvoidMain(string[]args){try{Process.Start("jconsole.exe");Console.WriteLine("Success!");}catch(Exceptione){Console.WriteLine("{0}Exceptioncaught.",e);}}}}如果我

c# - 如何从 ServiceController 确定 Windows.Diagnostics.Process

这是我的第一篇文章,所以让我先打个招呼吧!我正在编写一个Windows服务来监视同一台服务器上许多其他Windows服务的运行状态。我想扩展应用程序以打印服务的一些内存统计信息,但我无法弄清楚如何从特定的ServiceController对象映射到其关联的Diagnostics.Process对象,我认为我需要确定内存状态。我发现了如何从ServiceController映射到原始图像名称,但我正在监视的许多服务都是从同一图像启动的,因此这不足以确定进程。有谁知道如何从给定的ServiceController获取Process对象?也许通过确定服务的PID?或者是否有人对此问题有其他解

c# - Process.Start ("IEXPLORE.EXE") 在启动后立即触发 Exited 事件。为什么?

我在xp中安装IE8时遇到一个奇怪的问题。我试图在c#中使用System.Diagnostics.Process.Start方法启动IE。我需要捕获IE的退出事件并进行一些操作。但我最终遇到了一个相当奇怪的问题,即IE在启动后立即触发exited事件。这是示例代码ProcessobjProcess=Process.Start("IEXPLORE.EXE","http://google.com");if(objProcess!=null){objProcess.EnableRaisingEvents=true;objProcess.Exited+=newEventHandler(myPr

c# - "StandardOut has not been redirected or the process hasn' t started yet”在 C# 中读取控制台命令输出时

感谢@user2526830提供的代码。基于该代码,我在程序中添加了几行,因为我想读取SSH命令的输出。下面是我的代码,它在while行出错StandardOuthasnotbeenredirectedortheprocesshasn'tstartedyet.我想要实现的是,我想将ls的输出读入一个字符串。ProcessStartInfostartinfo=newProcessStartInfo();startinfo.FileName=@"f:\plink.exe";startinfo.Arguments="-sshabc@x.x.x.x-pwabc123";Processproce

c# - Process.Exited 并不总是触发

如果我运行以下代码:ProcessmyProcess=newSystem.Diagnostics.Process();myProcess.StartInfo.FileName="notepad.exe";myProcess.EnableRaisingEvents=true;myProcess.Exited+=newSystem.EventHandler(Process_OnExit);myProcess.Start();publicstaticvoidProcess_OnExit(objectsender,EventArgse){//Deletethefileonexit}当我退出记事

c# - 电子邮件删除附件后,错误 "The process cannot access the file because it is being used by another process."

我正在做一个电子邮件表单。电子邮件有附件,并在附加文件后发送电子邮件。接下来需要从服务器删除文件。当我试图获取文件时,它给了我主题错误。我什至在删除文件之前调用了GC.Collect(),但错误仍然存​​在。我删除文件的代码是:privatevoidDeleteFiles(DataTabledt){GC.Collect();String[]sAttachments=newString[dt.Rows.Count];try{sAttachments=newString[dt.Rows.Count];for(Int32J=0;J要将文件附加到电子邮件,我的代码是:oMess.Subject

c# - Process.StartInfo.Arguments 是否支持 UTF-8 字符串?

可以使用UTF-8字符串作为StartInfo的参数吗?我正在尝试将UTF-8(在本例中为日语字符串)作为控制台参数传递给应用程序。类似这样的东西(这只是一个例子!(cmd.exe将是一个自定义应用程序))varprocess=newSystem.Diagnostics.Process();process.StartInfo.Arguments="/K\"echoこれはテストです\"";process.StartInfo.FileName="cmd.exe";process.StartInfo.UseShellExecute=true;process.Start();process.W