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#,希望大牛指点迷津,不胜感激!!

cera:秋季美国便宜VPS促销,低至24/月起,多款VPS配置,自带免费Windows

介绍:819云怎么样?819云创办于2019,由一家从2017年开始从业的idc行业商家创办,主要从事云服务器,和物理机器819云—-带来了9月最新的秋季便宜vps促销活动,一共4款便宜vps,从2~32G内存,支持Windows系统,…高速建站的美国vps位于洛杉矶cera机房,服务器接入1Gbps带宽,采用魔方管理系统,适合新手玩耍!官方网站:https://www.8...

2021年全新Vultr VPS主机开通云服务器和选择机房教程(附IP不通问题)

昨天有分享到"2021年Vultr新用户福利注册账户赠送50美元"文章,居然还有网友曾经没有注册过他家的账户,薅过他们家的羊毛。通过一阵折腾居然能注册到账户,但是对于如何开通云服务器稍微有点不对劲,对于新人来说确实有点疑惑。因为Vultr采用的是预付费充值方式,会在每月的一号扣费,当然我们账户需要存留余额或者我们采用自动扣费支付模式。把笔记中以前的文章推送给网友查看,他居然告诉我界面不同,看的不对...

3C云1核1G 9.9元 4核4G 16元 美国Cera 2核4G 24元

3C云互联怎么样?3C云互联专注免备案香港美国日本韩国台湾云主机vps服务器,美国高防CN2GIA,香港CN2GIA,顶级线路优化,高端品质售后无忧!致力于对互联网云计算科技深入研发与运营的极客共同搭建而成,将云计算与网络核心技术转化为最稳定,安全,高速以及极具性价比的云服务器等产品提供给用户!专注为个人开发者用户,中小型,大型企业用户提供一站式核心网络云端服务部署,促使用户云端部署化简为零,轻松...

useshellexecute为你推荐
dota启动项dota2启动选项怎么设置fps手机号收验证码为什么我的手机收不到验证码站群是什么意思什么叫网站站群阿里云如何重装系统怎么重装系统cdn有什么用国内有哪些靠谱的 Javascript 库 CDN可用xshell教程请问安卓有什么软件具有xshell的功能海外idc我想做境外IDC 主营VPS服务 我需要什么 境外独服linux比较廉价 刚刚起家希望给个廉价的方案!快云服务器快云VPS速度怎么样?好看的表格样式创意如何使用PS快速制作美观的表格payoneer卡官网登录递四方后台怎么绑定payoneer卡
asp主机 北京vps 中国万网域名 瓦工 kvmla debian6 免费美国空间 环聊 西安主机 ledlamp 测试网速命令 学生机 winserver2008r2 傲盾代理 g6950 ddos攻击器下载 戴尔主机 ftp服务器架设 web服务器搭建软件 百度空间登陆首页 更多