用C#调外Delphi写的EXE(为了程序运行快,所以用Delphi),当Net程序结束后,调用的EXE也结整
这个代码怎么写呀?
我的C#调用外部的代码如下        Process process3 = new Process();
        public Form1()
        {
            InitializeComponent();
        }        private void button1_Click(object sender, EventArgs e)
        {
            
            this.process3.StartInfo.Domain = "";
            this.process3.StartInfo.FileName = "c:\\Project1.exe";
            this.process3.StartInfo.LoadUserProfile = false;
            this.process3.StartInfo.Password = null;
            this.process3.StartInfo.StandardErrorEncoding = null;
            this.process3.StartInfo.StandardOutputEncoding = null;
            this.process3.StartInfo.UserName = "";
            this.process3.SynchronizingObject = this;
            process3.Start();
        }

解决方案 »

  1.   

    可通过两种方法利用   Process   组件停止进程。使用哪种方法取决于所停止的进程的类型:     
        
      如果进程有图形用户界面,则调用   CloseMainWindow   方法。该方法向进程的主窗口发送一个关闭请求,其行为与从用户界面中选择“关闭”命令相同。使用该方法使目标程序有机会在清除操作中提示用户保存任何没有保存的数据。     
        
      如果进程没有用户界面,则调用   Kill   方法。     
      注意   调用   Kill   方法将立即停止进程,而不提示保持更改的数据。任何没有保存的数据将丢失。   
      如果您希望组件在操作系统关闭进程时得到通知,必须将   EnableRaisingEvents   属性设置为   true。EnableRaisingEvents   属性用于在异步处理中向应用程序通知进程已退出。有关更多信息,请参阅   Process.EnableRaisingEvents   属性。   
        
        
      停止进程     
        
      调用   GetProcessByName   方法检索要停止的进程。     
      调用下列方法之一:     
      如果进程有用户界面,则调用   CloseMainWindow   方法。     
      如果进程无窗口,则调用   Kill   方法。     
      下面的示例显示如何调用   CloseMainWindow   方法来关闭本地计算机上当前运行的所有“记事本”实例:     
        
      //   C#   
      Process[]   myProcesses;   
      //   Returns   array   containing   all   instances   of   Notepad.   
      myProcesses   =   Process.GetProcessesByName("Notepad");   
      foreach(Process   myProcess   in   myProcesses){   
              myProcess.CloseMainWindow();   
      }   
        
        
      ms-help://MS.NETFrameworkSDK.CHS/cpguidenf/html/cptskStoppingProcesses.htm   
      

  2.   

    可不可以加到一个Appdomain里 
      

  3.   

    直接用Process.Start("c:\\Project1.exe");试试
      

  4.   


    private void button1_Click(object sender, EventArgs e)
            {
                this.process3.StartInfo.Domain = "";
                this.process3.StartInfo.FileName = "C:\\Program Files\\DAEMON Tools Lite\\daemon.exe";
                this.process3.StartInfo.LoadUserProfile = false;
                this.process3.StartInfo.Password = null;
                this.process3.StartInfo.StandardErrorEncoding = null;
                this.process3.StartInfo.StandardOutputEncoding = null;
                this.process3.StartInfo.UserName = "";
                this.process3.SynchronizingObject = this;
                process3.Start();
                this.processID = process3.Id;
            }
    protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
                Process.GetProcessById(processID).Kill();
            }刚刚测试过,可以