国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

C# 啟動外部程序的幾種方法

2019-11-17 02:58:00
字體:
來源:轉載
供稿:網友
C# 啟動外部程序的幾種方法
    1. 啟動外部程序,不等待其退出。    2. 啟動外部程序,等待其退出。    3. 啟動外部程序,無限等待其退出。    4. 啟動外部程序,通過事件監視其退出。    // using System.Diagnostics;    PRivate string appName = "calc.exe";    /// <summary>    /// 1. 啟動外部程序,不等待其退出    /// </summary>    private void button1_Click(object sender, EventArgs e)    {    Process.Start(appName);    MessageBox.Show(String.Format("外部程序 {0} 啟動完成!", this.appName), this.Text,    MessageBoxButtons.OK, MessageBoxIcon.Information);    }    /// <summary>    /// 2. 啟動外部程序,等待其退出    /// </summary>    private void button2_Click(object sender, EventArgs e)    {    try    {    Process proc = Process.Start(appName);    if (proc != null)    {    proc.WaitForExit(3000);    if (proc.HasExited) MessageBox.Show(String.Format("外部程序 {0} 已經退出!", this.appName), this.Text,    MessageBoxButtons.OK, MessageBoxIcon.Information);    else    {    // 如果外部程序沒有結束運行則強行終止之。    proc.Kill();    MessageBox.Show(String.Format("外部程序 {0} 被強行終止!", this.appName), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);    }    }    }    catch (ArgumentException ex)    {    MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);    }    }    /// <summary>    /// 3. 啟動外部程序,無限等待其退出    /// </summary>    private void button3_Click(object sender, EventArgs e)    {    try    {    Process proc = Process.Start(appName);    if (proc != null)    {    proc.WaitForExit();    MessageBox.Show(String.Format("外部程序 {0} 已經退出!", this.appName), this.Text,    MessageBoxButtons.OK, MessageBoxIcon.Information);    }    }    catch (ArgumentException ex)    {    MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);    }    }    /// <summary>    /// 4. 啟動外部程序,通過事件監視其退出    /// </summary>    private void button4_Click(object sender, EventArgs e)    {    try    {    //啟動外部程序    Process proc = Process.Start(appName);    if (proc != null)    {    //監視進程退出    proc.EnableRaisingEvents = true;    //指定退出事件方法    proc.Exited += new EventHandler(proc_Exited);    }    }    catch (ArgumentException ex)    {    MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);    }    }    /// <summary>    ///啟動外部程序退出事件    /// </summary>    void proc_Exited(object sender, EventArgs e)    {    MessageBox.Show(String.Format("外部程序 {0} 已經退出!", this.appName), this.Text,    MessageBoxButtons.OK, MessageBoxIcon.Information);


上一篇:Unity3d網格合并

下一篇:通過NPOI操作Excel

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 原阳县| 澄江县| 桃园县| 白山市| 宁化县| 江口县| 桂平市| 祁连县| 阳江市| 黄龙县| 阿拉善左旗| 嵊泗县| 永吉县| 任丘市| 泽普县| 扬州市| 土默特左旗| 安康市| 徐闻县| 开封县| 松原市| 安吉县| 阳曲县| 浦江县| 山阳县| 保德县| 龙南县| 锦屏县| 广饶县| 崇礼县| 天峻县| 平泉县| 玉屏| 遵义市| 浮梁县| 仁寿县| 达州市| 榆林市| 尚志市| 大理市| 南康市|