1. Sergey Antonov
  2. HgSccPackage

Commits

Sergey Antonov  committed 103033d

Added a check if process in any job allready before assigning it to a new job

  • Participants
  • Parent commits 47fd352
  • Branches default

Comments (0)

Files changed (1)

File HgSccHelper/ProcessWrapper/Job.cs

View file
  • Ignore whitespace
 //=========================================================================
 
 using System;
+using System.ComponentModel;
 using System.Runtime.InteropServices;
+using HgSccHelper;
 
 namespace ProcessWrapper
 {
 		[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
 		public static extern IntPtr CreateJobObject(IntPtr lpJobAttributes, string lpName);
 
-		[DllImport("kernel32.dll")]
+		[DllImport("kernel32.dll", SetLastError = true)]
 		public static extern bool AssignProcessToJobObject(IntPtr hJob, IntPtr hProcess);
 
 		[DllImport("kernel32.dll", EntryPoint = "SetInformationJobObject")]
 		[DllImport("kernel32.dll")]
 		public static extern void CloseHandle(IntPtr handle);
 
+		[DllImport("kernel32.dll")]
+		public static extern bool IsProcessInJob(IntPtr Process, IntPtr Job, out bool Result);
+
 		IntPtr job;
 
 		//-----------------------------------------------------------------------------
 		//-----------------------------------------------------------------------------
 		public bool AssignProcessToJob(Process proc)
 		{
+			bool is_process_in_job;
+			if (IsProcessInJob(proc.Handle, IntPtr.Zero, out is_process_in_job))
+			{
+				if (is_process_in_job)
+				{
+					Logger.WriteLine("Process is allready in job");
+				}
+			}
+
 			return AssignProcessToJobObject(job, proc.Handle);
 		}