最近,我在构建我的程序时变得更加健康,我观察到大多数程序需要2或3分钟才能执行,当我检查任务调度程序时,我发现它们消耗了100%的CPU使用率,可以我在代码中以编程方式限制了这种用法?这肯定会让我在给定的时间运行多个程序.
谢谢,Nidhi
我正在努力拼凑一个pinvoke'ing CreateJobObject和SetInformationJobObject的工作示例.通过各种谷歌搜索(包括俄罗斯和中国的帖子!)我拼凑了以下代码.我认为JOBOBJECT_BASIC_LIMIT_INFORMATION的定义基于平台(32/64位)而变化.CreateJobObject/AssignProcessToJobObject 似乎工作.SetInformationJobObject失败 - 错误24或87.
Process myProcess // POPULATED SOMEWHERE ELSE
// Create Job & assign this process and another process to the job
IntPtr jobHandle = CreateJobObject( null , null );
AssignProcessToJobObject( jobHandle , myProcess.Handle );
AssignProcessToJobObject( jobHandle , Process.GetCurrentProcess().Handle );
// Ensure that killing one process kills the others
JOBOBJECT_BASIC_LIMIT_INFORMATION limits = new JOBOBJECT_BASIC_LIMIT_INFORMATION();
limits.LimitFlags = (short)LimitFlags.JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
IntPtr pointerToJobLimitInfo = Marshal.AllocHGlobal( Marshal.SizeOf( limits ) );
Marshal.StructureToPtr( limits , pointerToJobLimitInfo , false );
SetInformationJobObject( job , JOBOBJECTINFOCLASS.JobObjectBasicLimitInformation , …Run Code Online (Sandbox Code Playgroud)