system.diagnostics

How to get the output of a System.Diagnostics.Process?

浪尽此生 提交于 2019-11-26 13:48:57
问题 I run ffmpeg like this: System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo = new System.Diagnostics.ProcessStartInfo(ffmpegPath, myParams); p.Start(); p.WaitForExit(); ... but the problem is that the console with ffmpeg pops up and disappears right away, so I can't get any feedback. I don't even know if the process ran correctly. So how can I either: Tell the console to stay opened Retrieve in the C# what the console displayed 回答1: What you need to do is capture the

Using PerformanceCounter to track memory and CPU usage per process?

我只是一个虾纸丫 提交于 2019-11-26 12:59:11
问题 How can I use System.Diagnostics.PerformanceCounter to track the memory and CPU usage for a process? 回答1: For per process data: Process p = /*get the desired process here*/; PerformanceCounter ramCounter = new PerformanceCounter("Process", "Working Set", p.ProcessName); PerformanceCounter cpuCounter = new PerformanceCounter("Process", "% Processor Time", p.ProcessName); while (true) { Thread.Sleep(500); double ram = ramCounter.NextValue(); double cpu = cpuCounter.NextValue(); Console

How can I programmatically limit my program's CPU usage to below 70%?

别来无恙 提交于 2019-11-26 10:17:02
问题 Of late, I\'m becoming more health oriented when constructing my program, I have observed that most of programs take 2 or 3 minutes to execute and when I check on the task scheduler, I see that they consume 100% of CPU usage, can I limit this usage programatically in code? This will certainly enable me to run multiple programs at a given time. Thanks, Nidhi 回答1: That's not your concern... It's the job of the operating system to distribute processor time between running processes. If you'd

Why is this process crashing as soon as it is launched?

前提是你 提交于 2019-11-26 09:40:04
问题 We have an IIS WCF service that launches another process (app.exe) as a different user. I have complete control over both applications (and this is a dev environment for now). The IIS app pool runs as me, a domain user (DOMAIN\\nirvin), who is also a local administrator on the box. The second process is supposed to run as a local user (svc-low). I am using System.Diagnostics.Process.Start(ProcessStartInfo) to launch the process. The process launches successfully - I know because there are no

How to execute process on remote machine, in C#

这一生的挚爱 提交于 2019-11-26 04:26:25
问题 How can I start a process on a remote computer in c#, say computer name = \"someComputer\", using System.Diagnostics.Process class? I created a small console app on that remote computer that just writes \"Hello world\" to a txt file, and I would like to call it remotely. Console app path: c:\\MyAppFolder\\MyApp.exe Currently I have this: ProcessStartInfo startInfo = new ProcessStartInfo(string.Format(@\"\\\\{0}\\{1}\", someComputer, somePath); startInfo.UserName = \"MyUserName\"; SecureString

How can I find the method that called the current method?

吃可爱长大的小学妹 提交于 2019-11-25 22:57:07
问题 When logging in C#, how can I learn the name of the method that called the current method? I know all about System.Reflection.MethodBase.GetCurrentMethod() , but I want to go one step beneath this in the stack trace. I\'ve considered parsing the stack trace, but I am hoping to find a cleaner more explicit way, something like Assembly.GetCallingAssembly() but for methods. 回答1: Try this: using System.Diagnostics; // Get call stack StackTrace stackTrace = new StackTrace(); // Get calling method