C# winfrom 当前程序内存读取和控制

https://zhidao.baidu.com/question/31914620.html

 

https://www.cnblogs.com/xcsn/p/4678322.html

 

Process CurrentProcess = Process.GetCurrentProcess();
CurrentProcess.Id.ToString();//PID
((Double)(CurrentProcess.TotalProcessorTime.TotalMilliseconds-CurrentProcess.UserProcessorTime.TotalMilliseconds)).ToString();//CPU
(CurrentProcess.WorkingSet64 / 1024 / 1024).ToString() + "M (" + (CurrentProcess.WorkingSet64 / 1024).ToString() + "KB)";//占用内存
CurrentProcess.Threads.Count.ToString();//线程

 

 

#region 内存回收
[DllImport("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize")] public static extern int SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize); ///  /// 释放内存 ///  public static void ClearMemory() { GC.Collect(); GC.WaitForPendingFinalizers(); if (Environment.OSVersion.Platform == PlatformID.Win32NT) { App.SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1); } } #endregion

转载于:https://www.cnblogs.com/LuoEast/p/9447575.html

你可能感兴趣的:(C# winfrom 当前程序内存读取和控制)