system.diagnostics

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

久未见 提交于 2019-11-30 05:39:40
问题 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

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

徘徊边缘 提交于 2019-11-30 05:31:22
问题 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 回答1: 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

Open Windows' Calculator in my C# Win Application?

大城市里の小女人 提交于 2019-11-29 18:45:46
问题 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 ? 回答1: 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

FileVersionInfo.GetVersionInfo() incorrect in Console Application

余生颓废 提交于 2019-11-29 15:07:50
I'm getting some serious weirdness using FileVersionInfo.GetVersionInfo() and was hoping somebody might be able to help. The basics of the issue is that I am iterating through all the files in a folder calling GetVersionInfo() on each. There are about 300 files. This works ok for all but 2 of the files. For these DLLs I am getting comepletely incorrect info back from GetVersionInfo(). In order to eliminate all other variables, I extracted this call into a simple test app and it still got the same problem. However, if I built the test app as a Windows Application (it was a Console Application

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

断了今生、忘了曾经 提交于 2019-11-29 13:27:33
问题 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,

Process.Start a file without Extension

…衆ロ難τιáo~ 提交于 2019-11-29 10:20:26
We already know how System.Diagnostics.Process.Start("C:\filename.png") works, but what if the file name doesn't end with an extension? How can I run a filename without an extension, using the default program that is associated with, for example, a .png extension? Something like: openFile("C:\filename","PNG") You can of course patch together the FileName and the Extension and hope for the best. Or test whether a file Extension has a predefined Opener, an entry in the Registry that associates an Extension with an application that can hadle that file format. The System provides an API -

Calling dism.exe from System.Diagnostics.Process Fails

馋奶兔 提交于 2019-11-29 09:44:41
For enabling Microsoft-Hyper-V and Microsoft-Hyper-V-Management in Windows 2008 R2 Server(64bit), I'm calling dism.exe as a process. The command I've used is Dism.exe /online /Get-FeatureInfo /FeatureName:Microsoft-Hyper-V Dism.exe /online /Get-FeatureInfo /FeatureName:Microsoft-Hyper-V-Management-Clients This works fine when I execute this from the command line but it fails when I try to execute it through my code. I've tried the 64bit version of Dism.exe under the C:\Windows\SysWoW64 folder but it fails too. Here is the error message I get, You cannot service a running 64-bit operating

Get CPU and RAM usage

强颜欢笑 提交于 2019-11-29 09:10:46
问题 I need to get the ram memory and CPU usage during execution of a process (the process can run sometimes and over 30 minutes). I am able to get the free RAM but the CPU usage it's not correct, compared with the value from task manager. Am I doing something wrong? Here is my code: class Program { static List<float> AvailableCPU = new List<float>(); static List<float> AvailableRAM = new List<float>(); protected static PerformanceCounter cpuCounter; protected static PerformanceCounter ramCounter;

How do I run a Console Application, capture the output and display it in a Literal?

吃可爱长大的小学妹 提交于 2019-11-29 02:46:47
I see that I can start processes with System.Diagnostics.Process. I'm trying with the following code, but its not working. The page just hangs and I have to restart IIS... using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Diagnostics; public partial class VideoTest : System.Web.UI.Page { List<string> outputLines = new List<string>(); bool exited = false; protected void Page_Load(object sender, EventArgs e) { string AppPath = Request.PhysicalApplicationPath; Process myProcess = new Process(); myProcess.StartInfo

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

非 Y 不嫁゛ 提交于 2019-11-28 10:09:11
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 has not been modified by another thread). The program runs successfully. While researching other