示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="threshold"></param>
        /// <returns></returns>
        public static bool IsProcessMemoryTight(uint threshold)
        {
            string component = "ProcessMemory";
            bool   results   = false;

            try
            {
                IntPtr handle = Process.GetCurrentProcess().Handle;
                PPROCESS_MEMORY_COUNTERS counters = new PPROCESS_MEMORY_COUNTERS();
                if (GetProcessMemoryInfo(handle, counters, counters.cb))
                {
                    ErrorLog.DebugLog("Page Fault Count: " + counters.PageFaultCount, component);
                    ErrorLog.DebugLog("Page File Usage: " + counters.PagefileUsage, component);
                    ErrorLog.DebugLog("Peak Page File Usage: " + counters.PeakPagefileUsage, component);
                    ErrorLog.DebugLog("Peak Working Set Size: " + counters.PeakWorkingSetSize, component);
                    ErrorLog.DebugLog("Private Usage: " + counters.PrivateUsage, component);
                    ErrorLog.DebugLog("Working Set Size: " + counters.WorkingSetSize, component);

                    results = counters.PagefileUsage > threshold;
                }
            }
            catch (Exception ex)
            {
                ErrorLog.LogError(ex.Message, new CallingMethod());
            }
            return(results);
        }
示例#2
0
 static extern bool GetProcessMemoryInfo([In] IntPtr handle, [In, Out] PPROCESS_MEMORY_COUNTERS counters, [In] uint cb);