Usage of EmptyWorkingSet now via the configuration, so we don't use it for all people.

This commit is contained in:
RKrom 2014-06-16 23:32:30 +02:00
parent 9cc485243f
commit 9aefc90460
3 changed files with 22 additions and 14 deletions

View file

@ -19,20 +19,32 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using log4net;
namespace GreenshotPlugin.UnmanagedHelpers {
/// <summary>
/// Description of PsAPI.
/// </summary>
public class PsAPI {
private static readonly ILog LOG = LogManager.GetLogger(typeof(PsAPI));
[DllImport("psapi", SetLastError = true, CharSet=CharSet.Unicode)]
public static extern uint GetModuleFileNameEx(IntPtr hProcess, IntPtr hModule, StringBuilder lpFilename, uint nSize);
[DllImport("psapi", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern uint GetProcessImageFileName(IntPtr hProcess, StringBuilder lpImageFileName, uint nSize);
[DllImport("psapi")]
public static extern int EmptyWorkingSet(IntPtr hwProc);
private static extern int EmptyWorkingSet(IntPtr hwProc);
/// <summary>
/// Make the process use less memory by emptying the working set
/// </summary>
public static void EmptyWorkingSet() {
LOG.Info("Calling EmptyWorkingSet");
using (Process currentProcess = Process.GetCurrentProcess()) {
EmptyWorkingSet(currentProcess.Handle);
}
}
}
}