Recent

Author Topic: I need winexec via Active ProcExp as Running until the end.  (Read 424 times)

d2010

  • Sr. Member
  • ****
  • Posts: 264
I need winexec via Active ProcExp as Running until the end.
« on: December 17, 2025, 01:01:14 pm »
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)
 8)
  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,
 
Code: C++  [Select][+][-]
  1.   public static void ThrottleProcess(int processId, double limit)
  2.     { // You see here typeB..
  3.         var process = Process.GetProcessById(processId);
  4.         var processName = process.ProcessName;
  5.         var p = new PerformanceCounter("Process", "% Processor Time", processName);
  6.         while (true)
  7.         {
  8.             var interval = 100;
  9.             Thread.Sleep(interval);
  10.  
  11.             var currentUsage = p.NextValue() / Environment.ProcessorCount;
  12.             if (currentUsage < limit) continue;
  13.             var suspensionTime = (currentUsage-limit) / currentUsage * interval;
  14.             SuspendProcess(processId);
  15.             Thread.Sleep((int)suspensionTime);
  16.             ResumeProcess(processId);
  17.         }
  18.     }
  19.  
c)Other type of task? You have other purpose?
Code: [Select]
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
            }
        }
    }
}

« Last Edit: January 03, 2026, 12:05:12 pm by d2010 »

dbannon

  • Hero Member
  • *****
  • Posts: 3809
    • tomboy-ng, a rewrite of the classic Tomboy
Re: I need winexec
« Reply #1 on: December 17, 2025, 11:31:51 pm »
d2010, I think you may have misunderstood the thrust of this topic.

(Have a look at linpack, it might do as badley as 70% on windows, don't know, never tried.)

Davo

Edit : seems someone broke this off into a new thread without leaving a note to that effect.
« Last Edit: December 18, 2025, 01:03:20 am by dbannon »
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

 

TinyPortal © 2005-2018