zoukankan      html  css  js  c++  java
  • C#软件监控外部程序运行状态

    需要外挂一个程序,用于监控另一个程序运行状态,一旦检测到另一程序关闭,就触发一个事件做其他处理。

    引用的类

    1
    using System.Diagnostics;//引入Process 类 

    声明

    1
    private Process[] MyProcesses; 

      主要处理部分,该段代码可放在定时器中循环检测监控的程序是否启动

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    MyProcesses = Process.GetProcessesByName("SajetManager");//需要监控的程序名,该方法带出该程序所有用到的进程 
    foreach (Process myprocess in MyProcesses) 
        textBox1.Text += myprocess.ProcessName + " "
        if (myprocess.ProcessName.ToLower() == "sajetmanager"
        
            MessageBox.Show("SajetManager"); 
            myprocess.EnableRaisingEvents = true;//设置进程终止时触发的时间 
            myprocess.Exited += new EventHandler(myprocess_Exited);//发现外部程序关闭即触发方法myprocess_Exited 
        
    }  <br><br>
    1
    2
    3
    4
    private void myprocess_Exited(object sender, EventArgs e)//被触发的程序 
        MessageBox.Show("SajetManager close"); 
    }
     
     
  • 相关阅读:
    css做导航
    css和div
    表格技巧
    HTML表单
    ASP.NET MVC 中的强类型控件
    Aspose.Cells导入与导出excel
    webpack 入门
    asp.net my sqlHelper
    visual studio下用mysql数据库建EF遇到的问题及解决方法
    asp.net mvc 无刷新高效分页
  • 原文地址:https://www.cnblogs.com/webenh/p/9796699.html
Copyright © 2011-2022 走看看