useshellexecute如何正确的终止正在运行的子线程

useshellexecute  时间:2021-05-19  阅读:()

您好。用 System.Diagnostics.Process.Start 怎么样来打开一个Word文档或者PDf文件呢、

System.Diagnostics.Process p = new System.Diagnostics.Process(); //采用操作系统自动识别的模式 p.StartInfo.UseShellExecute = true; //要打开的文件路径,可以是WORD,EXCEL,PDF,TXT等等 p.StartInfo.FileName = @"d:a.doc"; p.StartInfo.Verb = "open"; //开始 p.Start();

C#调用DOS命令怎么把变值代入,并且可以运行

我给段代码,是做命令行重定向的。

可以改成你的需求

string results = null; System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();

psi.FileName = System.Environment.GetEnvironmentVariable("ComSpec");

psi.RedirectStandardInput = false; psi.RedirectStandardOutput = true; psi.UseShellExecute = false;

psi.CreateNoWindow = true; string cmd = "dir"; psi.Arguments = "/c " + cmd;

System.Diagnostics.Process p = System.Diagnostics.Process.Start(psi);

results = p.StandardOutput.ReadToEnd();

//Console.WriteLine(results);

p.WaitForExit(); MessageBox .Show (results);

C# 中如何使用DOS命令执行操作?

C#代码如下: Process p = new Process(); p.StartInfo.FileName = "cmd.exe"; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.CreateNoWindow = false; //true表示不显示黑框,false表示显示dos界面 p.Start(); String dosCommand= "mkdir test"; p.StandardInput.WriteLine(dosCommand); p.Close();

C#中怎么写运行 事件方法

这样筏乏摧何诋蛊搓坍掸开: mandText = "cmd"; System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.StartInfo.FileName =mandText; proc.StartInfo.UseShellExecute = true; proc.Start(); 关于你说的attrib,由于attrib是DOS的命令,而不是独立执行文件,必须用以下的方法: mandText = "cmd"; System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.StartInfo.Arguments = "/C attrib h:\123 -s -h"; proc.StartInfo.FileName =mandText; proc.StartInfo.UseShellExecute = true; proc.Start(); 其实要修改文件的属性有另一方法: System.IO.File.SetAttributes("h:\123", System.IO.FileAttributes.Normal);

如何正确的终止正在运行的子线程

我的代码是这样的。



在多线程的子线程的调用方法里这样运行gethaha.exe,str1 是传递过来的参数。



Process process = new System.Diagnostics.Process(); process.StartInfo.FileName = "gethaha.exe"; process.StartInfo.Arguments = str1; process.StartInfo.UseShellExecute = false; // 必须禁用操作系统外壳程序 process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardOutput = true; process.EnableRaisingEvents = true; process.Start(); System.IO.StreamReader reader = process.StandardOutput;//截取输出流 string line = reader.ReadLine();//每次读取一行 while (!reader.EndOfStream) { Console.WriteLine(line + " "); line = reader.ReadLine();} process.WaitForExit(10000); if(process.HasExited ==false) process.Kill(); reader.Close(); 我的意思是我想在每个线程里运行gethaha.exe 每个运行10秒钟如果10秒后它没有执行完毕就终止它 问题1:可是运行中过了10秒后它并不终止,process.KIll() 没管用,而且我把主程序关了,gethaha.exe仍然在后台执行。

到底是哪没有考虑到; 问题2:还有那个重定向输出流,我想让它gethaha.exe输出一句Console就输出一句,现在的代码是gethaah.exe 执行完了,主程序把gethaah.exe输出的一次性全部输出出来。





就这两个问题即使我再加上这两句代码也不顶用process.Dispose(); Application.Exit(); Thread.CurrentThread.Abort(); 它仍然在后台运行。



苦恼啊。



小弟初学c#,希望大牛指点迷津,不胜感激!!

wordpress外贸企业主题 wordpress经典外贸企业建站主题

WordPress经典外贸企业建站主题,经典配色扁平化简约设计+跨屏自适应移动端设备,特色外贸企业建站功能模块+在线Inquiry询单功能,更有利于Google等英文搜索优化和站点收录。采用标准的HTML5+CSS3语言开发,兼容当下的各种主流浏览器: IE 6+(以及类似360、遨游等基于IE内核的)、Firefox、Google Chrome、Safari、Opera等;同时支持移动终端的常用...

Sparkedhost($8/月)美国迈阿密AMD Ryzen高性能VPS;免费100G高防

sparkedhost怎么样?sparkedhost主机。Sparkedhost于2017年7月注册在美国康涅狄格州,2018年收购了ClynexHost,2019年8月从Taltum Solutions SL收购了The Beast Hosting,同年10月从Reilly Bauer收购了OptNode Hosting。sparkedhost当前的业务主要为:为游戏“我的世界”提供服务器、虚拟...

麻花云-香港CN2云服务器,安徽BGP线路,安徽移动大带宽!全系6折!

一、麻花云官网点击直达麻花云官方网站二、活动方案优惠码:专属优惠码:F1B07B 享受85折优惠。点击访问活动链接最新活动 :五一狂欢 惠战到底 香港云主机 1.9折起香港特价体验云主机CN2 云服务器最新上线KVM架构,,默认40G SSD,+10G自带一个IPv4,免费10Gbps防御,CPU内存带宽价格购买1核1G1M19元首月链接2核2G 2M92元/3个月链接2核4G3M112元/3个月...

useshellexecute为你推荐
魔兽世界配置要求玩魔兽世界电脑配置要求是怎样的?查看硬盘大小如何在电脑上查看硬盘是多大?接收验证码的手机号现在新浪微博注册时填写的接收验证码的手机号是怎么回事?自动绑定了吗?阿里云vps如何购买阿里巴巴机房从哪买?我浏览一个网站速度好,Ip显示阿里巴巴机房,从哪里买这样的vps?阿里云建站费用阿里巴巴快速回款费用如何计算和收取?国内云盘国内的企业网盘哪个好?payoneer卡官网登录递四方后台怎么绑定payoneer卡io域名注册id域名怎么注册?域名解析记录值填什么解析域名用A记录好呢还是cname好呢?jsp的虚拟主机java虚拟主机,jsp的语言用哪种空间呢
国外网站空间 西安电信测速 私服服务器 163网 php主机 css样式大全 一元域名 java空间 html空间 亚洲小于500m 云全民 福建天翼加速 php空间申请 空间合租 申请网站 上海电信测速 浙江服务器 免费个人主页 测速电信 服务器硬件配置 更多