Process启动.exe,当.exe内部抛出异常时,总会弹出一个错误提示框,阻止Process进入结束
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进入结束的更多相关文章
- 用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 ...
- Java_Swing程序设计_尝试开发一个登陆窗体,包括用户名、密码以及提交按钮和重置按钮,当用户输入用户名my,密码love时,弹出登陆成功提示对话框。
package com.lzw; import java.awt.*;import java.awt.event.*; import javax.swing.*; public class UseCa ...
- 文件夹名为单字符时右击弹出C++错误
原因:操作系统安装有虚拟光驱软件——WinMount,此错误为WinMount的一个Bug 解决方法: 打开Windows注册表,定位此注册表并删除即可 [HKEY_CLASSES_ROOT\Dire ...
- skyline添加wfs服务时,弹出错误“no layers were found”!
1.问题描述: 使用TerraExplorer Pro添加ArcGIS Server 10.2发布的WFS服务图层时,弹出如下错误: 2.错误原因: 发布wfs服务前,图层数据源的空间参考未设置,不能 ...
- 使你的ActiveX控件执行时不弹出安全性提示(转载)
我们编写一个ActiveX控件在IE中运行,一般会弹出一个安全提示,如何避免这种情况?下面是我在参考前人的文章后,总结出“在浏览器中执行时不弹出警告的ActiveX控件”的两种编写方法,予以备忘.注意 ...
- Eric6中编译窗体时,弹出提示:无法启动pyuic5的解决方案
用 Eric6 与 PyQt5 结合,非常方便的实现界面与逻辑分离,满足python的极速GUI编程,不需要在界面上花很多时间. 这是一对GUI开发完美的组合! Eric6中设计窗体时,弹出提示:‘无 ...
- 如何禁用MySql总是定时弹出一个MySQLInstallerConsole.exe的窗口
如何禁用MySql总是定时弹出一个MySQLInstallerConsole.exe的窗口 禁用mysql总是弹出一个安装框的定时任务这一条安装命令,Installing MySQL 5.6.21 u ...
- 联想E440问题:点击鼠标时,弹出“无法连接synaptics定点装置驱动程序”错误
笔记本:Levono E440 问题描述: 在控制面板中,点击鼠标时,弹出“无法连接synaptics定点装置驱动程序”错误,如何解决? 即使在安装联想的驱动后,也没办法解决 解决步骤: 1. ...
- 【SD系列】SAP 查看销售订单时,报了一个错误消息,“项目不符合计划行(程序错误)”
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[SD系列]SAP 查看销售订单时,报了一个错误 ...
随机推荐
- ThinkPHP中的三大自动简介
ThinkPHP中的三大自动简介 文章TAG:thinkphp 自动简介 时间:2014-08-23来源:商业源码网 作者:源码库 文章热度: 186 ℃ 过期已备案域名,注册就能用!终身VIP会员, ...
- PHP抓取采集类snoopy介绍
PHP抓取采集类snoopy介绍 一个PHP的抓取方案 在 2011年07月04日 那天写的 已经有 10270 次阅读了 感谢 参考或原文 服务器君一共花费了14.288 ms进行了2次 ...
- XBox 开发者大会
今天参加了微软的Xbox开发者大会,虽然没我什么事情,不过还是有不少的收获,随便说说自己的一点感受吧. 先上几张图,附带妹子一个,不过手机不清楚哈,~~ 1 ID@XBOX开发者计划与独立游戏开发者 ...
- 20个C语言中常用宏定义总结
01: 防止一个头文件被重复包含 #ifndef COMDEF_H#define COMDEF_H//头文件内容#endif 02: 重新定义一些类型防止由于各种平台和编译器的不同,而产生的类型字节数 ...
- smoke
1.Have a smoke? 2.Would you like a cigarette? 3.Cigarettes? 4.Let's go have a smoke. 5.Do you smoke ...
- thinkPhp 3.1.3的验证码无法显示的问题
Image帮助类的output方法中,在下面的代码 header("Content-type: image/" . $type); 前增加代码: ob_end_clean();
- Nginx的配置中与流量分发相关的配置规范:
1.除首页外,其他页面都在某个目录中首页可以直接在根目录下,其他页面都要在根目录下的目录中.不同的location尽量使用第一个dir的模式进行区分,便于区分该流量是落在nginx本地,还是转发到后端 ...
- C# Json时间类型的转换
DateTime dt1 = new DateTime(1970, 1, 1); dt1 = dt1.AddMilliseconds(long.Parse(list.Items[i].UpdatedA ...
- 变长数组列表ArrayList
简介:此数据结构定义为一个ArrayList结构体类型,维护了一个内部堆数组.通过realloc函数实现了数组容量自动扩充,每次扩充到原来的2倍. 通过函数指针实现了使用者根据自己的需求按条件按查找目 ...
- mysql 存储过程--- 创建,调用,删除
DELIMITER //CREATE PROCEDURE p_addscore(nums INT,OUT retrows INT)BEGINDECLARE i INT DEFAULT 0;add_lo ...