Exemplo n.º 1
0
        public JobObject(string jobObjectName)
        {
            if (string.IsNullOrEmpty(jobObjectName))
            {
                jobObjectName = null;
            }

            this.name = jobObjectName;

            this.jobHandle = NativeMethods.CreateJobObject(IntPtr.Zero, jobObjectName);
            if (this.jobHandle.IsInvalid)
            {
                if (jobObjectName == null)
                {
                    int error = Marshal.GetLastWin32Error();
                    throw new Win32Exception(error, "CreateJobObject failed.");
                }
                else
                {
                    // JOB_OBJECT_ALL_ACCESS = 0x1F001F
                    this.jobHandle = NativeMethods.OpenJobObject(0x1F001F, false, jobObjectName);
                    if (this.jobHandle.IsInvalid)
                    {
                        int error = Marshal.GetLastWin32Error();
                        throw new Win32Exception(error, "OpenJobObject failed.");
                    }
                }
            }

            this.UpdateExtendedLimit();
        }
Exemplo n.º 2
0
        public static JobObject Attach(string jobObjectName)
        {
            if (string.IsNullOrEmpty(jobObjectName))
            {
                throw new ArgumentNullException("jobObjectName");
            }

            JobObjectHandle jobHandle = null;

            JobObject result     = null;
            JobObject tempResult = null;

            try
            {
                // JOB_OBJECT_ALL_ACCESS = 0x1F001F
                jobHandle = NativeMethods.OpenJobObject(0x1F001F, false, jobObjectName);

                if (jobHandle.IsInvalid)
                {
                    int error = Marshal.GetLastWin32Error();
                    throw new Win32Exception(error, "Failed to open job object.");
                }

                tempResult = new JobObject(jobHandle, jobObjectName);

                jobHandle  = null;
                result     = tempResult;
                tempResult = null;
            }
            finally
            {
                if (jobHandle != null)
                {
                    jobHandle.Dispose();
                }

                if (tempResult != null)
                {
                    tempResult.Dispose();
                }
            }

            return(result);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JobObject"/> class. No Windows Job Object is created.
 /// </summary>
 private JobObject(JobObjectHandle jobObject, string jobObjectName)
 {
     this.jobHandle = jobObject;
     this.name      = jobObjectName;
 }
Exemplo n.º 4
0
 public static extern bool AssignProcessToJobObject(JobObjectHandle hJob, IntPtr hProcess);
Exemplo n.º 5
0
 public static extern bool TerminateJobObject(JobObjectHandle hJob, uint uExitCode);
Exemplo n.º 6
0
 public static extern bool SetInformationJobObject(JobObjectHandle hJob, JobObjectInfoClass JobObjectInfoClass, IntPtr lpJobObjectInfo, uint cbJobObjectInfoLength);
Exemplo n.º 7
0
 public static extern bool QueryInformationJobObject(JobObjectHandle hJob, JobObjectInfoClass JobObjectInformationClass, IntPtr lpJobObjectInfo, uint cbJobObjectInfoLength, IntPtr lpReturnLength);
Exemplo n.º 8
0
 public static extern bool TerminateJobObject(JobObjectHandle hJob, uint uExitCode);
Exemplo n.º 9
0
 public static extern bool IsProcessInJob(IntPtr Process, JobObjectHandle hJob, [MarshalAs(UnmanagedType.Bool)] out bool Result);
Exemplo n.º 10
0
 public static extern bool QueryInformationJobObject(JobObjectHandle hJob, JobObjectInfoClass JobObjectInformationClass, IntPtr lpJobObjectInfo, uint cbJobObjectInfoLength, IntPtr lpReturnLength);
Exemplo n.º 11
0
 public static extern bool AssignProcessToJobObject(JobObjectHandle hJob, IntPtr hProcess);
Exemplo n.º 12
0
 public static extern bool SetInformationJobObject(JobObjectHandle hJob, JobObjectInfoClass JobObjectInfoClass, IntPtr lpJobObjectInfo, uint cbJobObjectInfoLength);
Exemplo n.º 13
0
 public static extern bool IsProcessInJob(IntPtr Process, JobObjectHandle hJob, [MarshalAs(UnmanagedType.Bool)] out bool Result);
Exemplo n.º 14
0
        public static JobObject Attach(string jobObjectName)
        {
            if (string.IsNullOrEmpty(jobObjectName))
            {
                throw new ArgumentNullException("jobObjectName");
            }

            JobObjectHandle jobHandle = null;

            JobObject result = null;
            JobObject tempResult = null;

            try
            {
                // JOB_OBJECT_ALL_ACCESS = 0x1F001F
                jobHandle = NativeMethods.OpenJobObject(0x1F001F, false, jobObjectName);

                if (jobHandle.IsInvalid)
                {
                    int error = Marshal.GetLastWin32Error();
                    throw new Win32Exception(error, "Failed to open job object.");
                }

                tempResult = new JobObject(jobHandle, jobObjectName);

                jobHandle = null;
                result = tempResult;
                tempResult = null;
            }
            finally
            {
                if (jobHandle != null)
                {
                    jobHandle.Dispose();
                }

                if (tempResult != null)
                {
                    tempResult.Dispose();
                }
            }

            return result;
        }
Exemplo n.º 15
0
        public JobObject(string jobObjectName)
        {
            if (string.IsNullOrEmpty(jobObjectName))
            {
                jobObjectName = null;
            }

            this.name = jobObjectName;

            this.jobHandle = NativeMethods.CreateJobObject(IntPtr.Zero, jobObjectName);
            if (this.jobHandle.IsInvalid)
            {
                if (jobObjectName == null)
                {
                    int error = Marshal.GetLastWin32Error();
                    throw new Win32Exception(error, "CreateJobObject failed.");
                }
                else
                {
                    // JOB_OBJECT_ALL_ACCESS = 0x1F001F
                    this.jobHandle = NativeMethods.OpenJobObject(0x1F001F, false, jobObjectName);
                    if (this.jobHandle.IsInvalid)
                    {
                        int error = Marshal.GetLastWin32Error();
                        throw new Win32Exception(error, "OpenJobObject failed.");
                    }
                }
            }

            this.UpdateExtendedLimit();
        }
Exemplo n.º 16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JobObject"/> class. No Windows Job Object is created.
 /// </summary>
 private JobObject(JobObjectHandle jobObject, string jobObjectName)
 {
     this.jobHandle = jobObject;
     this.name = jobObjectName;
 }