首页 新闻 赞助 找找看

如何通过一个程序启动另一个程序

0
悬赏园豆:5 [已关闭问题] 关闭于 2012-05-06 19:38

我有个程序winform A,他有时候会发生异常死掉。我想做一个程序winfromB,他每隔10分钟自动检测程序A是否死掉,如果死掉就启动程序A,然后执行程序A主窗体中的一个函数GetModel。请问我如何实现?

时间都去哪了的主页 时间都去哪了 | 初学一级 | 园豆:51
提问于:2012-05-01 16:30
< >
分享
所有回答(2)
0
/// <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);    }}
無限遐想 | 园豆:3740 (老鸟四级) | 2012-05-01 16:44

代码格式乱了,最修改一下

支持(0) 反对(0) artwl | 园豆:16736 (专家六级) | 2012-05-01 16:53

@artwl: 你直接 拷貝代碼 放到c#的類里,一下就看清楚了。

支持(0) 反对(0) 無限遐想 | 园豆:3740 (老鸟四级) | 2012-05-02 09:27
0

建议你使用windows Service

邀月 | 园豆:25475 (高人七级) | 2012-05-01 18:11
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册