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

819云互联(800元/月),香港BGP E5 2650 16G,日本 E5 2650 16G

819云互联 在本月发布了一个购买香港,日本独立服务器的活动,相对之前的首月活动性价比更高,最多只能享受1个月的活动 续费价格恢复原价 是有些颇高 这次819云互联与机房是合作伙伴 本次拿到机房 活动7天内购买独立服务器后期的长期续费价格 加大力度 确实来说这次的就可以买年付或者更长时间了…本次是5个机房可供选择,独立服务器最低默认是50M带宽,不限制流量,。官网:https://ww...

Virtono:圣何塞VPS七五折月付2.2欧元起,免费双倍内存

Virtono是一家成立于2014年的国外VPS主机商,提供VPS和服务器租用等产品,商家支持PayPal、信用卡、支付宝等国内外付款方式,可选数据中心共7个:罗马尼亚2个,美国3个(圣何塞、达拉斯、迈阿密),英国和德国各1个。目前,商家针对美国圣何塞机房VPS提供75折优惠码,同时,下单后在LET回复订单号还能获得双倍内存的升级。下面以圣何塞为例,分享几款VPS主机配置信息。Cloud VPSC...

HostKvm:夏季优惠,香港云地/韩国vps终身7折,线路好/机器稳/适合做站

hostkvm怎么样?hostkvm是一家国内老牌主机商家,商家主要销售KVM架构的VPS,目前有美国、日本、韩国、中国香港等地的服务,站长目前还持有他家香港CN2线路的套餐,已经用了一年多了,除了前段时间香港被整段攻击以外,一直非常稳定,是做站的不二选择,目前商家针对香港云地和韩国机房的套餐进行7折优惠,其他套餐为8折,商家支持paypal和支付宝付款。点击进入:hostkvm官方网站地址hos...

useshellexecute为你推荐
小米云服务器登录你好 我想咨询下 要登录小米云服务除了手机信息验证还有其他方法吗?域名如何绑定服务器在啊里云买的域名与服务器怎么绑定云服务器搭建华为云服务器怎么搭建FTP服务器硬防专家你好,我想租一个免备案+硬防的服务器。硬防大概要30G左右 有便宜又好用的推荐吗?谢谢拉hnd-132关于人大HND宿舍住宿条件……施乐700施乐700代码010-342求高手指点bandwagonstation wagon是什么意思那好问一首歌:歌词有..........离家的人流浪在远方,没有那好衣裳没有那好烟..........dc4电脑中ASCLL码是 指什么?在线图片换背景照片手机自动换背景
长沙虚拟主机 美国linux主机 免费申请网页 服务器评测 老鹰主机 腾讯云数据库 nerd 申请空间 浙江独立 e蜗牛 域名转接 泉州电信 域名和空间 常州联通宽带 博客域名 google搜索打不开 香港博客 godaddyssl 建站技术 cdn加速 更多