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);
|
HandleDataTransport(dataTransport);
|
||||||
}
|
}
|
||||||
// Make Greenshot use less memory after startup
|
// Make Greenshot use less memory after startup
|
||||||
EmptyWorkingSet();
|
if (_conf.MinimizeWorkingSetSize) {
|
||||||
|
PsAPI.EmptyWorkingSet();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1253,8 +1255,7 @@ namespace Greenshot {
|
||||||
|
|
||||||
if (path != null) {
|
if (path != null) {
|
||||||
try {
|
try {
|
||||||
using (Process process = Process.Start(path)) {
|
using (Process.Start(path)) {}
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
// Make sure we show what we tried to open in the exception
|
// Make sure we show what we tried to open in the exception
|
||||||
ex.Data.Add("path", path);
|
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>
|
/// <summary>
|
||||||
/// Do work in the background
|
/// Do work in the background
|
||||||
|
@ -1395,8 +1388,7 @@ namespace Greenshot {
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void BackgroundWorkerTimerTick(object sender, EventArgs e) {
|
private void BackgroundWorkerTimerTick(object sender, EventArgs e) {
|
||||||
if (_conf.MinimizeWorkingSetSize) {
|
if (_conf.MinimizeWorkingSetSize) {
|
||||||
LOG.Info("Calling EmptyWorkingSet");
|
PsAPI.EmptyWorkingSet();
|
||||||
EmptyWorkingSet();
|
|
||||||
}
|
}
|
||||||
if (UpdateHelper.IsUpdateCheckNeeded()) {
|
if (UpdateHelper.IsUpdateCheckNeeded()) {
|
||||||
LOG.Debug("BackgroundWorkerTimerTick checking for update");
|
LOG.Debug("BackgroundWorkerTimerTick checking for update");
|
||||||
|
|
|
@ -77,6 +77,10 @@ namespace Greenshot.Helpers {
|
||||||
_windows = null;
|
_windows = null;
|
||||||
_selectedCaptureWindow = null;
|
_selectedCaptureWindow = null;
|
||||||
_capture = null;
|
_capture = null;
|
||||||
|
// Empty working set after capturing
|
||||||
|
if (conf.MinimizeWorkingSetSize) {
|
||||||
|
PsAPI.EmptyWorkingSet();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public static void CaptureClipboard() {
|
public static void CaptureClipboard() {
|
||||||
using (CaptureHelper captureHelper = new CaptureHelper(CaptureMode.Clipboard)) {
|
using (CaptureHelper captureHelper = new CaptureHelper(CaptureMode.Clipboard)) {
|
||||||
|
|
|
@ -19,20 +19,32 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using log4net;
|
||||||
|
|
||||||
namespace GreenshotPlugin.UnmanagedHelpers {
|
namespace GreenshotPlugin.UnmanagedHelpers {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Description of PsAPI.
|
/// Description of PsAPI.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class PsAPI {
|
public class PsAPI {
|
||||||
|
private static readonly ILog LOG = LogManager.GetLogger(typeof(PsAPI));
|
||||||
[DllImport("psapi", SetLastError = true, CharSet=CharSet.Unicode)]
|
[DllImport("psapi", SetLastError = true, CharSet=CharSet.Unicode)]
|
||||||
public static extern uint GetModuleFileNameEx(IntPtr hProcess, IntPtr hModule, StringBuilder lpFilename, uint nSize);
|
public static extern uint GetModuleFileNameEx(IntPtr hProcess, IntPtr hModule, StringBuilder lpFilename, uint nSize);
|
||||||
[DllImport("psapi", SetLastError = true, CharSet = CharSet.Unicode)]
|
[DllImport("psapi", SetLastError = true, CharSet = CharSet.Unicode)]
|
||||||
public static extern uint GetProcessImageFileName(IntPtr hProcess, StringBuilder lpImageFileName, uint nSize);
|
public static extern uint GetProcessImageFileName(IntPtr hProcess, StringBuilder lpImageFileName, uint nSize);
|
||||||
[DllImport("psapi")]
|
[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