Пример #1
0
 public JobHandle()
 {
     InteropMethods.SECURITY_ATTRIBUTES empty = default;
     myJobHandle = InteropMethods.CreateJobObject(ref empty, null);
     if (myJobHandle == IntPtr.Zero)
     {
         throw new ApplicationException("Unable to create job object");
     }
 }
Пример #2
0
        public ProcessHandle(string commandLine)
        {
            InteropMethods.SECURITY_ATTRIBUTES empty       = default;
            InteropMethods.PROCESS_INFORMATION processInfo = default;
            var startupInfo = new InteropMethods.STARTUPINFO
            {
                cb = Marshal.SizeOf <InteropMethods.STARTUPINFO>(),
            };
            var created = InteropMethods.CreateProcess(null, commandLine, ref empty, ref empty, false,
                                                       InteropMethods.ProcessCreationFlags.CREATE_NO_WINDOW |
                                                       InteropMethods.ProcessCreationFlags.CREATE_SUSPENDED,
                                                       IntPtr.Zero, null, ref startupInfo, out processInfo);

            if (!created)
            {
                throw new ArgumentException("Can't create process");
            }

            myProcessHandle = processInfo.hProcess;
            myThreadHandle  = processInfo.hThread;
        }