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. navicat for mysql 10.1.7注册码

    终于找到一个可用的了:名,组织,注册码都是:NAVN-LNXG-XHHX-5NOO 还有一个 注册码:NAVH-WK6A-DMVK-DKW3名称和组织不用填写   好像都可以用

  2. buffer overflow vulnerabilitie

    Computer Systems A Programmer's Perspective Second Edition Avoiding security holes.For many years,bu ...

  3. 后台list 如何转换为json格式

    request.setCharacterEncoding("utf-8"); response.setCharacterEncoding( "UTF-8"); ...

  4. url如何传递参数

    $(document).ready(function() { var name=getQueryString('minename'); if (name != null && name ...

  5. Android TextView 显示不全的自动补齐方式

    TextView在Android开发中用到的地方应该是很多的.很多时候,TextView会有一行显示不全被截取或者会换行.之前我的解决办法比较笨拙,定死TextView的一行字数长度,最后一个以省略号 ...

  6. 实例讲述PHP面向对象的特性;;;php中const与define的使用区别

    php中const与define的使用区别 1.const:类成员变量定义,一旦定义且不能改变其值. define:定义全局常量,在任何地方都可以访问.2.define:不能在类中定义,而const可 ...

  7. 弹窗文件js+css

    // 每个弹窗的标识 var x =0; var idzt = new Array(); var Window = function(config){ //ID不重复 idzt[x] = " ...

  8. c语言学习感想

    接触c语言已经2个多月了,在这段期间按时的完成了作业,上课能够较好的听讲,因此我获得了老师奖励的小黄衫. 同时,希望自己能够学好c语言! 学习感受与心得 因为兴趣,选择了计算机这专业,我从遥远的南方来 ...

  9. 【android学习3】解决Android界面布局添加EditView之后无法预览问题

    在设计登陆界面时,拖入一个EditView之后发现界面无法预览 问题分析: 进入xml源文件里发现一个警告,提示添加inputType或者hint元素,添加后界面仍然无法预览... 仔细查看了当前使用 ...

  10. node express 学习1

    参考链接https://cnodejs.org/topic/55ece31004e2cdb230671c50 express-session connect-nongo mongoose 1.安装mo ...