system.diagnostics

TraceSource and TraceListener quietly fail to do anything

无人久伴 提交于 2019-12-01 14:32:18
How do I troubleshoot System.Diagnostics trace when it quietly fails to do anything at all? I'm so glad you asked! This problem happened to me recently. I suspected something in the chain of TraceSwitch es, TraceSource s and TraceListener s had gone awry. But with no trace and no error messages, I needed more information. The authors of the BCL helpfully put all the diagnostic information in a private list whose values disappear when ever the garbage collector feels like it. Still, the info was good enough and accessible via reflection. It turned out that I had several TraceSource 's but the

.NET How to check if a Windows process is running as an “App” or as a “Background application”

梦想与她 提交于 2019-12-01 07:36:40
问题 On Windows 8.1 you go into the task manager and check the list of processes, there are two lists: - One for "Apps", which are visible foreground apps - One for "Background processes", which are processes running in the background My end goal is to time how long it takes an application to load. When the application is still loading, it appears in "Background processes". However, once loaded, it appears in "Apps". This is going to be my criteria on what constitutes an app finishing loading. I

PerformanceCounter.NextValue hangs on some machines

不羁的心 提交于 2019-12-01 07:16:47
I don't know why, but many computers hangs on following operation: void Init() { net1 = new List<PerformanceCounter>(); net2 = new List<PerformanceCounter>(); foreach (string instance in new PerformanceCounterCategory("Network Interface").GetInstanceNames()) { net1.Add(new PerformanceCounter("Network Interface", "Bytes Received/sec", instance)); net2.Add(new PerformanceCounter("Network Interface", "Bytes Sent/sec", instance)); } } //Once in 1 second void UpdateStats() { Status.Text = ""; for (int i = 0; i < net1.Count; i++) Status.Text += string.Format("{0}/{1} Kb/sec; ", net1[i].NextValue() /

Automatically log System.diagnostics.trace messages to an Nlog target

元气小坏坏 提交于 2019-12-01 03:40:38
Say you have C# trace messages all over an application. Something like: Trace.TraceInformation("Service Started"); How do you automatically log this to an nLog target without having to add code like the following to all the classes that have trace messages? using NLog; private static Logger logger = LogManager.GetCurrentClassLogger(); Is there a way to do this without including traces produced by the .NET Framework itself, which this article demonstrates how to do? This works for cases where there isn't an explicit source <system.diagnostics> <trace autoflush="true" indentsize="4"> <listeners>

Starting a Jar file using System.Diagnostics.Process

非 Y 不嫁゛ 提交于 2019-12-01 00:00:58
I have a jar file which I want to run from within C#. Here's what I have so far: clientProcess.StartInfo.FileName = @"java -jar C:\Users\Owner\Desktop\myJarFile.jar"; clientProcess.StartInfo.Arguments = "[Something]"; clientProcess.Start(); clientProcess.WaitForExit(); int exitCode = clientProcess.ExitCode; Unfortunatly I get "System could not find specified file", which makes sense since its not a file its a command. I've seen code online which tells you to use: System.Diagnostics.Process.Start("java -jar myprog.jar"); However I need the return codes AND I need to wait for it to exit. Thanks.

can't understand .net 2010 tracing and app.config

半世苍凉 提交于 2019-11-30 21:24:17
In my app.config I want to set 3 tracing levels (switches?): verbose, warning and none. In the debug version of the code, I want the verbose switch to be active, in the release I want warning. In special cases my application users can modify the config file to disable all traces. I want debug traces to output on the console, while release traces only to a log file. I',ve written the following: [...] <system.diagnostics> <sources> <!-- This section defines the logging configuration for My.Application.Log --> <source name="debug" switchName="debug"> <listeners> <add name="FileLog"/> <add name=

How to determine whether a System.Diagnostics.Process is 32 or 64 bit?

ぐ巨炮叔叔 提交于 2019-11-30 20:56:57
I tried: process.MainModule.FileName.Contains("x86") But it threw an exception for a x64 process: Win32Exception: Only a part of the ReadProcessMemory ou WriteProcessMemory request finished You need to call IsWow64Process via P/Invoke: [DllImport( "kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi )] [return: MarshalAs( UnmanagedType.Bool )] public static extern bool IsWow64Process( [In] IntPtr processHandle, [Out, MarshalAs( UnmanagedType.Bool )] out bool wow64Process ); Here's a helper to make it a bit easier to call: public static bool Is64BitProcess( this

Starting a Jar file using System.Diagnostics.Process

你说的曾经没有我的故事 提交于 2019-11-30 18:39:09
问题 I have a jar file which I want to run from within C#. Here's what I have so far: clientProcess.StartInfo.FileName = @"java -jar C:\Users\Owner\Desktop\myJarFile.jar"; clientProcess.StartInfo.Arguments = "[Something]"; clientProcess.Start(); clientProcess.WaitForExit(); int exitCode = clientProcess.ExitCode; Unfortunatly I get "System could not find specified file", which makes sense since its not a file its a command. I've seen code online which tells you to use: System.Diagnostics.Process

Open Windows' Calculator in my C# Win Application?

*爱你&永不变心* 提交于 2019-11-30 13:24:50
I know I can open Windows Calculator with the following code : System.Diagnostics.Process.Start("calc"); But I wanna open it in my C# Win Application, i.e : I don't want to open it in the independent window, I wanna open it in my window. How can I do it ? You cannot embed another application into your form. However, you can move the calculator window on top of your form and set your form as its parent. This might accomplish the visual effect that you're looking for. You might check into the SetParent API function. For example: System.Diagnostics.Process p = System.Diagnostics.Process.Start(

Check if a process is running on a remote system using C#

送分小仙女□ 提交于 2019-11-30 09:05:36
I am trying to check if a process is running on a remote system. I am using the following code: string procSearc = "notepad"; string remoteSystem = "remoteSystemName"; Process[] proce = System.Diagnostics.Process.GetProcessesByName(procSearch, remoteSystem); However, when I try to run the code, I get the following error: "Couldn't connect to remote machine." I am able to run pslist with the following command: C:>pslist \remoteSystemName So I know it is possible to get the information I need, but I need it in the code. Another possibility would be to integrate pslist into C# and search the list