gtk2 uses xwayland in that case, and that can be real PITA.
SubTitle = I need winexec of ("chkdsk.exe") with max cpu-occupied of cpu Any one can translate these lines to Lazarus?
I need declare same task both type
a)TypeA short time and user leave control Cpu occupied to any value(free-for-All).
b)TypeB long time but set allways to cpu70%occupied or cpu30%..70% max all times. If i set cpu to 30% format Hdd need min3hours, and I can work inside "Lazarus.exe". (good-solution)
If i set cpu to 80% format Hdd need 1,6hour(s), and I can not work inside "Lazarus.exe", not "Lazarus" (bad solution)
E.g. format HDD, Scan HDD for bad-sectors, copy 200GB to other HDD, etc.
make 7Zip archive for entire Hdd. Max, until full operation is done, min3 hours in my computer But I can work 3hours with "lazarus.exe"
I am happy,
, until I got the End ,
Scan with AVGconsole entire disk for viruses,
public static void ThrottleProcess(int processId, double limit)
{ // You see here typeB..
var process = Process.GetProcessById(processId);
var processName = process.ProcessName;
var p = new PerformanceCounter("Process", "% Processor Time", processName);
while (true)
{
var interval = 100;
Thread.Sleep(interval);
var currentUsage = p.NextValue() / Environment.ProcessorCount;
if (currentUsage < limit) continue;
var suspensionTime = (currentUsage-limit) / currentUsage * interval;
SuspendProcess(processId);
Thread.Sleep((int)suspensionTime);
ResumeProcess(processId);
}
}
c)Other type of task? You have other purpose?
internal class ProcessManagement
{
private static int CpuPercentageLimit { get; set; }
public static void StartProcess(int cpuPercent)
{
CpuPercentageLimit = cpuPercent;
var stopwatch = new Stopwatch();
while (true)
{
stopwatch.Reset();
stopwatch.Start();
var actionStart = stopwatch.ElapsedTicks;
try
{
var myProcess = new Process
{
StartInfo =
{
FileName = @"D:\\Source\\ExeProgram\\ExeProgram\\bin\\Debug\\ExeProgram.exe",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
}
};
myProcess.Start();
myProcess.PriorityClass = ProcessPriorityClass.Idle;
myProcess.Refresh();
myProcess.WaitForExit();
var actionEnd = stopwatch.ElapsedTicks;
var actionDuration = actionEnd - actionStart;
long relativeWaitTime = (int)((1 / (double)CpuPercentageLimit) * actionDuration);
var sleepTime = (int)((relativeWaitTime / (double)Stopwatch.Frequency) * 1000);
Thread.Sleep(sleepTime);
myProcess.Close();
}
catch (Exception e)
{
// ignored
}
}
}
}