Beispiel #1
0
 /// <summary>
 /// Helper function to add a process to the job object
 /// </summary>
 /// <param name="handle">Handle of the process to be added</param>
 public void AddProcess(IntPtr handle)
 {
     if (this.jobHandle != IntPtr.Zero)
     {
         if (!WinAPI.AssignProcessToJobObject(this.jobHandle, handle))
         {
             EqtTrace.Warning("AddProcess : Failed to AddProcess {0}", Marshal.GetLastWin32Error());
         }
     }
     else
     {
         EqtTrace.Warning("AddProcess : Ignoring as job object is not created");
     }
 }
Beispiel #2
0
        /// <summary>
        ///     Assigns the given process to this Job Object.
        /// </summary>
        /// <param name="process">Process to assign to this Job Object.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="process"/> is <c>null</c>.</exception>
        /// <exception cref="InvalidOperationException">
        ///     Thrown if <paramref name="process"/> already belongs to a Job Object.
        /// </exception>
        /// <exception cref="Win32Exception">
        ///     Thrown if the operating system was unable to assign <paramref name="process"/> to the Job Object.
        /// </exception>
        public void Assign(Process process)
        {
            if (process == null)
            {
                throw new ArgumentNullException("process");
            }

            if (AlreadyAssigned(process))
            {
                return;
            }

            if (HasJobObject(process))
            {
                throw new InvalidOperationException(
                          "Requested process already belongs to another job group.  Check http://stackoverflow.com/a/4232259/3205 for help.");
            }

            PInvokeUtils.Try(() => WinAPI.AssignProcessToJobObject(_jobObjectHandle, process.Handle));
        }