Forum

Пожалуйста or Регистрация для создания сообщений и тем.

Автоочистка при достижении %

PreviousPage 2 of 3Next
static int MemoryEmptyWorkingSets = 2;
 static extern uint NtSetSystemInformation(int InfoClass, ref int Info, int Length);
public static int EmptyWorkingSet()
{
    using (var current = WindowsIdentity.GetCurrent(TokenAccessLevels.Query | TokenAccessLevels.AdjustPrivileges))
    {
        TokPriv1Luid newst; newst.Count = 1; newst.Luid = 0L; newst.Attr = 2;
        if (!LookupPrivilegeValue(null, "SeProfileSingleProcessPrivilege", ref newst.Luid)) { return 1; }
        if (!AdjustTokenPrivileges(current.Token, false, ref newst, 0, IntPtr.Zero, IntPtr.Zero)) { return 2; }
        NtSetSystemInformation(80, ref MemoryEmptyWorkingSets, Marshal.SizeOf(2));
    }
    return 0;
}

Скажи ты мог бы попробовать с этим методом

if (busyRam / totalRam * 100 >= 30)
{
    MemoryClean.EmptyWorkingSet();
}

 

По Моему Ты что-то не докинул *скрин*

Сори 

public static int SystemInfoLength;
public static GCHandle gcHandle;
[DllImport("advapi32", SetLastError = true)]
static extern bool LookupPrivilegeValue(string host, string name, ref long pluid);
[DllImport("advapi32", SetLastError = true)]
static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall, ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen);
[DllImport("ntdll", SetLastError = true)]
static extern uint NtSetSystemInformation(int InfoClass, ref int Info, int Length);

первые две вроде не нужны

Это какая-то библиотека? *скрин*

все забыл ))

struct TokPriv1Luid
{
    public int Count;
    public long Luid;
    public int Attr;
}

 

У Меня выводит 0

Без messagebox просто EmptyWorkingSet();

Форма спокойно запускается

Спасибо что помог, я много времени отнял у тебя, дальше буду пробовать сам ))))

Удачи! 👍

admin отреагировал на эту запись.
admin
PreviousPage 2 of 3Next