system.diagnostics

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

╄→гoц情女王★ 提交于 2019-11-27 07:47:27
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 Lucas Jones What you need to do is capture the Standard Output stream: p.StartInfo.RedirectStandardOutput = true; p.StartInfo.UseShellExecute =

Using PerformanceCounter to track memory and CPU usage per process?

时间秒杀一切 提交于 2019-11-27 06:59:04
How can I use System.Diagnostics.PerformanceCounter to track the memory and CPU usage for a process? 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.WriteLine("RAM: "+(ram/1024/1024)+" MB; CPU: "+(cpu)+" %"); } Performance counter also has other counters than

.NET Process Start Process Error using credentials (The handle is invalid)

五迷三道 提交于 2019-11-27 06:01:47
问题 I have an Windows Form application that supplies the User Name, Domain, and Password to the StartInfo, and it throws this: System.ComponentModel.Win32Exception: The handle is invalid at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start() When I allow the credentials to default to current user I get no such error, and the process I start works to the extent that it doesn't need to use credentials (the creds are necessary for

Is CorrelationManager.LogicalOperationStack compatible with Parallel.For, Tasks, Threads, etc

北战南征 提交于 2019-11-27 03:23:59
问题 Please see this question for background information: How do Tasks in the Task Parallel Library affect ActivityID? That question asks how Tasks affect Trace.CorrelationManager.ActivityId. @Greg Samson answered his own question with a test program showing that ActivityId is reliable in the context of Tasks. The test program sets an ActivityId at the beginning of the Task delegate, sleeps to simulate work, then checks the ActivityId at the end to make sure that it is the same value (i.e. that it

How get value of parameters in stacktrace

做~自己de王妃 提交于 2019-11-27 02:44:57
问题 I can get information about a parameter by StackTrace using something like this: catch (Exception ex) { var st = new StackTrace(ex); System.Reflection.ParameterInfo pi = st.GetFrame(0).GetMethod().GetParameters().First(); } I want know how i get the value of parameter. Example: If my method in stack trace was like: void MyMethod(object value) And the call was like: MyMethod(10); I want to get the value 10. How i do that? 回答1: There are two ways. The more powerful is the COM API for .NET

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

隐身守侯 提交于 2019-11-27 01:29:54
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 exceptions thrown, and I get a process ID. But the process dies immediately, and I get an error in the

Difference between ElapsedTicks, ElapsedMilliseconds, Elapsed.Milliseconds and Elapsed.TotalMilliseconds? (C#)

孤者浪人 提交于 2019-11-27 01:01:52
问题 I'm totally confused between these 4. What is the difference between ElapsedMilliseconds (long), ElapsedTicks (long), Elapsed.TotalMilliseconds (double) and Elapsed.Milliseconds (int)? I have a function { Stopwatch sw = new Stopwatch(); sw.Start(); MyTimeConsumingAction(); sw.Stop(); sw.//what? } How do I get the correct time consumed by my long running process from elapsed property of Stopwatch object in milliseconds? Edit: I tried msdn documentation but it isn't anything detailed there..

System.Diagnostics.Debug.WriteLine in production code

一世执手 提交于 2019-11-27 00:50:37
问题 I should probably know this already, but I'm not sure and I don't see it documented. I use System.Diagnostics.Debug.WriteLine quite often during the development process to be able to track changes to variables or exceptions as I'm debugging the code. This is meant to make development and understanding what's happening easier only during development. I normally either comment out the code or delete it when I go to production. I'm wondering what happens if I forget to comment the code out. Say,

How to translate MS Windows OS version numbers into product names in .NET?

偶尔善良 提交于 2019-11-27 00:41:13
问题 How to translate MS Windows OS version numbers into product names? For example, in .NET the following two properties could be used to work out that the product is MS Windows Vista Ultimate Edition : Environment.OSVersion.Platform returns Win32NT Environment.OSVersion.Version returns 6.0.6001.65536 回答1: howto net os version VB: Public Function GetOSVersion() As String Select Case Environment.OSVersion.Platform Case PlatformID.Win32S Return "Win 3.1" Case PlatformID.Win32Windows Select Case

How to execute process on remote machine, in C#

夙愿已清 提交于 2019-11-26 17:45:49
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 sec = new SecureString(); string pwd = "MyPassword"; foreach (char item in pwd) { sec.AppendChar(item); } sec