zoukankan      html  css  js  c++  java
  • C#调用Exe文件的方法及如何判断程序调用的exe已结束

    很简单的代码就可以实现C#调用EXE文件,如下:

    引入using System.Diagnostics;

    调用代码:

    Process.Start(exe文件名);

    或直接

    System.Diagnostics.Process.Start(exe文件名);

    C#如何判断程序调用的exe已结束

    二个方法:以运行系统记事本为例

    方法一:这种方法会阻塞当前进程,直到运行的外部程序退出
    System.Diagnostics.Process exep = System.Diagnostics.Process.Start(@"C:WindowsNotepad.exe");
    exep.WaitForExit();//关键,等待外部程序退出后才能往下执行
    MessageBox.Show("Notepad.exe运行完毕");

    方法二:为外部进程添加一个事件监视器,当退出后,获取通知,这种方法时不会阻塞当前进程,你可以处理其它事情
    System.Diagnostics.Process exep = new System.Diagnostics.Process();
    exep.StartInfo.FileName = @"C:WindowsNotepad.exe";
    exep.EnableRaisingEvents = true;
    exep.Exited += new EventHandler(exep_Exited);
    exep.Start();

    //exep_Exited事件处理代码,这里外部程序退出后激活,可以执行你要的操作
    void exep_Exited(object sender, EventArgs e)
    {
                MessageBox.Show("Notepad.exe运行完毕");
    }
  • 相关阅读:
    使用Eclipse的坑
    约定优于配置
    Tomcat服务器使用和debug
    spring框架排错
    spring框架学习感悟
    Spring的标签和验证等模块
    11. Container With Most Water
    1367. Linked List in Binary Tree
    486. Predict the Winner
    205. Isomorphic Strings
  • 原文地址:https://www.cnblogs.com/ArRan/p/3314799.html
Copyright © 2011-2022 走看看