mirror of
https://github.com/greenshot/greenshot
synced 2025-07-16 10:03:44 -07:00
Usage of EmptyWorkingSet now via the configuration, so we don't use it for all people.
This commit is contained in:
parent
9cc485243f
commit
9aefc90460
3 changed files with 22 additions and 14 deletions
|
@ -408,7 +408,9 @@ namespace Greenshot {
|
|||
HandleDataTransport(dataTransport);
|
||||
}
|
||||
// Make Greenshot use less memory after startup
|
||||
EmptyWorkingSet();
|
||||
if (_conf.MinimizeWorkingSetSize) {
|
||||
PsAPI.EmptyWorkingSet();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -1253,8 +1255,7 @@ namespace Greenshot {
|
|||
|
||||
if (path != null) {
|
||||
try {
|
||||
using (Process process = Process.Start(path)) {
|
||||
}
|
||||
using (Process.Start(path)) {}
|
||||
} catch (Exception ex) {
|
||||
// Make sure we show what we tried to open in the exception
|
||||
ex.Data.Add("path", path);
|
||||
|
@ -1379,14 +1380,6 @@ namespace Greenshot {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make the process use less memory by emptying the working set
|
||||
/// </summary>
|
||||
private void EmptyWorkingSet() {
|
||||
using (Process currentProcess = Process.GetCurrentProcess()) {
|
||||
PsAPI.EmptyWorkingSet(currentProcess.Handle);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Do work in the background
|
||||
|
@ -1395,8 +1388,7 @@ namespace Greenshot {
|
|||
/// <param name="e"></param>
|
||||
private void BackgroundWorkerTimerTick(object sender, EventArgs e) {
|
||||
if (_conf.MinimizeWorkingSetSize) {
|
||||
LOG.Info("Calling EmptyWorkingSet");
|
||||
EmptyWorkingSet();
|
||||
PsAPI.EmptyWorkingSet();
|
||||
}
|
||||
if (UpdateHelper.IsUpdateCheckNeeded()) {
|
||||
LOG.Debug("BackgroundWorkerTimerTick checking for update");
|
||||
|
|
|
@ -77,6 +77,10 @@ namespace Greenshot.Helpers {
|
|||
_windows = null;
|
||||
_selectedCaptureWindow = null;
|
||||
_capture = null;
|
||||
// Empty working set after capturing
|
||||
if (conf.MinimizeWorkingSetSize) {
|
||||
PsAPI.EmptyWorkingSet();
|
||||
}
|
||||
}
|
||||
public static void CaptureClipboard() {
|
||||
using (CaptureHelper captureHelper = new CaptureHelper(CaptureMode.Clipboard)) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue