public class TaskProcess
{
[DllImport("kernel32.dll", SetLastError = true)]
public static extern int SetErrorMode(int wMode); public Process process { get; set; } public void Do()
{
try
{
int oldMode = SetErrorMode(); this.process = new Process();
this.process.EnableRaisingEvents = true;
this.process.StartInfo.FileName = @"\\172.21.11.10\File\Platform\ExecuteFile\LSystem.exe";
this.process.StartInfo.Arguments = @"8 \\172.21.11.10\File\Platform\Configuration\AppSettings.config 17 1 0";
this.process.StartInfo.RedirectStandardError = true;
this.process.StartInfo.RedirectStandardInput = true;
this.process.StartInfo.RedirectStandardOutput = true;
this.process.StartInfo.CreateNoWindow = false;
this.process.StartInfo.ErrorDialog = false;
this.process.StartInfo.UseShellExecute = false;
this.process.Start(); SetErrorMode(oldMode); ThreadPool.QueueUserWorkItem(DoWork, process); process.WaitForExit(); Console.WriteLine("ExitCode is " + this.process.ExitCode);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
} public ArrayList Out = ArrayList.Synchronized(new ArrayList()); private void DoWork(object state)
{
Process process = state as Process; if (process != null)
{
try
{
string line = process.StandardOutput.ReadLine(); do
{
Out.Add(line); line = process.StandardOutput.ReadLine();
Console.WriteLine(line);
}
while (line != null); process.StandardInput.WriteLine("exit");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
}
}
}

参考文章:

http://stackoverflow.com/questions/673036/how-to-handle-a-crash-in-a-process-launched-via-system-diagnostics-process

Process启动.exe,当.exe内部抛出异常时,总会弹出一个错误提示框,阻止Process进入结束的更多相关文章

  1. 用MPLAB IDE编程时,软件总是弹出一个窗口提示: “the extended cpu mode configuration bit is enabled,but the program that was loaded was not built using extended cpu instructions. therefore,your code may not work properly

    用MPLAB IDE编程时,软件总是弹出一个窗口提示:"the extended cpu mode configuration bit is enabled,but the program ...

  2. Java_Swing程序设计_尝试开发一个登陆窗体,包括用户名、密码以及提交按钮和重置按钮,当用户输入用户名my,密码love时,弹出登陆成功提示对话框。

    package com.lzw; import java.awt.*;import java.awt.event.*; import javax.swing.*; public class UseCa ...

  3. 文件夹名为单字符时右击弹出C++错误

    原因:操作系统安装有虚拟光驱软件——WinMount,此错误为WinMount的一个Bug 解决方法: 打开Windows注册表,定位此注册表并删除即可 [HKEY_CLASSES_ROOT\Dire ...

  4. skyline添加wfs服务时,弹出错误“no layers were found”!

    1.问题描述: 使用TerraExplorer Pro添加ArcGIS Server 10.2发布的WFS服务图层时,弹出如下错误: 2.错误原因: 发布wfs服务前,图层数据源的空间参考未设置,不能 ...

  5. 使你的ActiveX控件执行时不弹出安全性提示(转载)

    我们编写一个ActiveX控件在IE中运行,一般会弹出一个安全提示,如何避免这种情况?下面是我在参考前人的文章后,总结出“在浏览器中执行时不弹出警告的ActiveX控件”的两种编写方法,予以备忘.注意 ...

  6. Eric6中编译窗体时,弹出提示:无法启动pyuic5的解决方案

    用 Eric6 与 PyQt5 结合,非常方便的实现界面与逻辑分离,满足python的极速GUI编程,不需要在界面上花很多时间. 这是一对GUI开发完美的组合! Eric6中设计窗体时,弹出提示:‘无 ...

  7. 如何禁用MySql总是定时弹出一个MySQLInstallerConsole.exe的窗口

    如何禁用MySql总是定时弹出一个MySQLInstallerConsole.exe的窗口 禁用mysql总是弹出一个安装框的定时任务这一条安装命令,Installing MySQL 5.6.21 u ...

  8. 联想E440问题:点击鼠标时,弹出“无法连接synaptics定点装置驱动程序”错误

    笔记本:Levono E440   问题描述: 在控制面板中,点击鼠标时,弹出“无法连接synaptics定点装置驱动程序”错误,如何解决? 即使在安装联想的驱动后,也没办法解决   解决步骤: 1. ...

  9. 【SD系列】SAP 查看销售订单时,报了一个错误消息,“项目不符合计划行(程序错误)”

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[SD系列]SAP 查看销售订单时,报了一个错误 ...

随机推荐

  1. thinkphp模型层Model、Logic、Service讲解

    thinkphp模型层Model.Logic.Service讲解 时间:2014-08-24 15:54:56   编辑:一切随缘   文章来源:php教程网 已阅读:771 次       js特效 ...

  2. javaWeb中struts开发——Bean标签

    1.struts标签库中常用标签 使用myeclise标签可以自动注入,其中,前三个是经常使用的,主要的是logic标签 2.Bean标签 Bean标签主要用来定义和访问JavaBean,在Strut ...

  3. Spring配置文件的读取

    1.配置文件的命名 Spring框架中的默认配置文件,建议命名为applicationContext.xml * 编写配置文件,默认位置有两个 ①src目录.②WEB-INF目录 2.Spring 配 ...

  4. Linux的权限说明

    Linux的权限不是很细致,只有RWX三种r(Read,读取):对文件而言,具有读取文件内容的权限:对目录来说,具有浏览目录的权限.w(Write,写入):对文件而言,具有新增,修改,删除文件内容的权 ...

  5. java NIO ;mvn

    http://ifeve.com/java-nio-scattergather/ mvn introduction(install,conf, proxy,plugin,samples) http:/ ...

  6. Java线程池的原理及几类线程池的介绍

    刚刚研究了一下线程池,如果有不足之处,请大家不吝赐教,大家共同学习.共同交流. 在什么情况下使用线程池? 单个任务处理的时间比较短 将需处理的任务的数量大 使用线程池的好处: 减少在创建和销毁线程上所 ...

  7. protobuf序列化、反序列化

    引用dllprotobuf-net.rar /// <summary> /// buf序列化 /// </summary> public static String Seria ...

  8. RTSP交互命令简介及过程参数描述

    目录 [hide] 1 RTSP消息格式 2 简单的rtsp交互过程 3 rtsp中常用方法 3.1 OPTION 3.2 DESCRIBE 3.3 SETUP 3.4 PLAY 3.5 PAUSE ...

  9. Spark Programming--Actions

    first def first(): T first返回RDD中的第一个元素,不排序. 例子: count def count(): Long count返回RDD中的元素数量 例子: reduce ...

  10. iOS获取设备型号、设备类型等信息

    摘自 :http://www.mamicode.com/info-detail-1165460.html 设备标识 关于设备标识,历史上盛行过很多英雄,比如UDID.Mac地址.OpenUDID等,然 ...