C#的Process类调用第三方插件实现PDF文件转SWF文件

2019-12-30 14:33:17于海丽

3.WaitForExit()方法:指示<see cref ='System.Diagnostics.Process'/>组件等待指定的毫秒数,以使相关联的进程退出。

具体介绍一下该方法的实现代码:


public bool WaitForExit(int milliseconds) { 
      SafeProcessHandle handle = null; 
     bool exited;
      ProcessWaitHandle processWaitHandle = null; 
      try {
        handle = GetProcessHandle(NativeMethods.SYNCHRONIZE, false);
        if (handle.IsInvalid) {
          exited = true; 
        }
        else { 
          processWaitHandle = new ProcessWaitHandle(handle); 
          if( processWaitHandle.WaitOne(milliseconds, false)) {
            exited = true; 
            signaled = true;
          }
          else {
            exited = false; 
            signaled = false;
          } 
        } 
      }
      finally { 
        if( processWaitHandle != null) {
          processWaitHandle.Close();
        }
 
        // If we have a hard timeout, we cannot wait for the streams
        if( output != null && milliseconds == -1) { 
          output.WaitUtilEOF(); 
        }
 
        if( error != null && milliseconds == -1) {
          error.WaitUtilEOF();
        }
 
        ReleaseProcessHandle(handle);
 
      } 

      if (exited && watchForExit) { 
        RaiseOnExited();
      }
      
      return exited; 
    }

internal ProcessWaitHandle( SafeProcessHandle processHandle): base() {
      SafeWaitHandle waitHandle = null; 
      bool succeeded = NativeMethods.DuplicateHandle(
        new HandleRef(this, NativeMethods.GetCurrentProcess()), 
        processHandle, 
        new HandleRef(this, NativeMethods.GetCurrentProcess()),
        out waitHandle, 
        0,
        false,
        NativeMethods.DUPLICATE_SAME_ACCESS);
 
      if (!succeeded) {
        Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); 
      } 

      this.SafeWaitHandle = waitHandle; 
    }

4.StartInfo属性:获取或设置要传递给 Process 的 Start 方法的属性。StartInfo 表示用于启动进程的一组参数。 调用 Start 时,StartInfo 用于指定要启动的进程。 唯一必须设置的 StartInfo 成员是 FileName 属性。

具体介绍一下该方法的实现代码:
 


 [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), MonitoringDescription(SR.ProcessStartInfo)] 
    public ProcessStartInfo StartInfo {
      get { 
        if (startInfo == null) { 
          startInfo = new ProcessStartInfo(this);
        } 
        return startInfo;
      }
      [ResourceExposure(ResourceScope.Machine)]
      set { 
        if (value == null) {
          throw new ArgumentNullException("value"); 
        } 
        startInfo = value;
      } 
    }

5.CreateNoWindow属性:获取或设置指示是否在新窗口中启动该进程的值。

具体介绍一下该方法的实现代码: