内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

C#啟動(dòng)外部程序的幾種方法

1. 啟動(dòng)外部程序,不等待其退出。

    2. 啟動(dòng)外部程序,等待其退出。

    3. 啟動(dòng)外部程序,無(wú)限等待其退出。

    4. 啟動(dòng)外部程序,通過(guò)事件監(jiān)視其退出。

    // using System.Diagnostics;

    private string appName = "calc.exe";

    /// <summary>

    /// 1. 啟動(dòng)外部程序,不等待其退出

    /// </summary>

    private void button1_Click(object sender, EventArgs e)

    {

    Process.Start(appName);

    MessageBox.Show(String.Format("外部程序 {0} 啟動(dòng)完成!", this.appName), this.Text,

    MessageBoxButtons.OK, MessageBoxIcon.Information);

    }

    /// <summary>

    /// 2. 啟動(dòng)外部程序,等待其退出

    /// </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} 已經(jīng)退出!", this.appName), this.Text,

    MessageBoxButtons.OK, MessageBoxIcon.Information);

    else

    {

    // 如果外部程序沒(méi)有結(jié)束運(yùn)行則強(qiáng)行終止之。

    proc.Kill();

    MessageBox.Show(String.Format("外部程序 {0} 被強(qiáng)行終止!", this.appName), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

    }

    }

    }

    catch (ArgumentException ex)

    {

    MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);

    }

    }

    /// <summary>

    /// 3. 啟動(dòng)外部程序,無(wú)限等待其退出

    /// </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} 已經(jīng)退出!", this.appName), this.Text,

    MessageBoxButtons.OK, MessageBoxIcon.Information);

    }

    }

    catch (ArgumentException ex)

    {

    MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);

    }

    }

    /// <summary>

    /// 4. 啟動(dòng)外部程序,通過(guò)事件監(jiān)視其退出

    /// </summary>

    private void button4_Click(object sender, EventArgs e)

    {

    try

    {

    //啟動(dòng)外部程序

    Process proc = Process.Start(appName);

    if (proc != null)

    {

    //監(jiān)視進(jìn)程退出

    proc.EnableRaisingEvents = true;

    //指定退出事件方法

    proc.Exited += new EventHandler(proc_Exited);

    }

    }

    catch (ArgumentException ex)

    {

    MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);

    }

    }

    /// <summary>

    ///啟動(dòng)外部程序退出事件

    /// </summary>

    void proc_Exited(object sender, EventArgs e)

    {

    MessageBox.Show(String.Format("外部程序 {0} 已經(jīng)退出!", this.appName), this.Text,

    MessageBoxButtons.OK, MessageBoxIcon.Information);

分享標(biāo)題:C#啟動(dòng)外部程序的幾種方法
鏈接分享:http://www.rwnh.cn/article38/ghcipp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、網(wǎng)站營(yíng)銷(xiāo)虛擬主機(jī)、營(yíng)銷(xiāo)型網(wǎng)站建設(shè)外貿(mào)網(wǎng)站建設(shè)、微信公眾號(hào)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都app開(kāi)發(fā)公司
呼玛县| 抚顺市| 东安县| 永兴县| 离岛区| 台州市| 峨山| 普安县| 苍溪县| 漳州市| 宝应县| 梅河口市| 广灵县| 彭阳县| 抚远县| 连城县| 遂昌县| 喀什市| 托克托县| 伊通| 凤城市| 尚志市| 武冈市| 东兴市| 西丰县| 施秉县| 读书| 辽源市| 绥德县| 金湖县| 琼海市| 贡山| 盐城市| 金平| 永登县| 迭部县| 屏南县| 彭山县| 深泽县| 巴楚县| 当雄县|