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云(240元)香港CN2 日本CN2 物理机 E5 16G 1T 20M 3IP

819云是我们的老熟人了,服务器一直都是稳定为主,老板人也很好,这次给大家带来了新活动,十分给力 香港CN2 日本CN2 物理机 E5 16G 1T 20M 3IP 240元0官方网站:https://www.819yun.com/ 特惠专员Q:442379204套餐介绍套餐CPU内存硬盘带宽IP价格香港CN2 (特价)E5 随机分配16G1T 机械20M3IP240元/月日本CN2 (...

2022年腾讯云新春采购季代金券提前领 领取满减优惠券和域名优惠

2022年春节假期陆续结束,根据惯例在春节之后各大云服务商会继续开始一年的促销活动。今年二月中旬会开启新春采购季的活动,我们已经看到腾讯云商家在春节期间已经有预告活动。当时已经看到有抢先优惠促销活动,目前我们企业和个人可以领取腾讯云代金券满减活动,以及企业用户可以领取域名优惠低至.COM域名1元。 直达链接 - 腾讯云新春采购活动抢先看活动时间:2022年1月20日至2022年2月15日我们可以在...

GigsGigsCloud:$16/月KVM-1GB/30GB/1TB/1.6T高防/洛杉矶CN2 GIA+AS9929

GigsGigsCloud是一家成立于2015年老牌国外主机商,提供VPS主机和独立服务器租用,数据中心包括美国洛杉矶、中国香港、新加坡、马来西亚和日本等。商家VPS主机基于KVM架构,绝大部分系列产品中国访问速度不错,比如洛杉矶机房有CN2 GIA、AS9929及高防线路等。目前Los Angeles - SimpleCloud with Premium China DDOS Protectio...

useshellexecute为你推荐
华为云终端华为ARS-ALOO这一款手机多少钱?魔兽世界配置要求魔兽世界配置要求dota启动项steam上的能不能像dota一样设置启动项进国服vps和云主机哪个好想搭建一个离线秒赞平台,用服务器搭建好还是用空间好,服务器硬防专家你好,我想租一个免备案+硬防的服务器。硬防大概要30G左右 有便宜又好用的推荐吗?谢谢拉服务器日志分析软件有没有好点的IIS分析工具 求救!!!!!华为云服务登录电脑版华为账户必须要华为手机登入吗?ck香港官网正品香港ck专柜代购calvin kleinkj06cb0101要多少钱?银色款!云服务器ecs什么意思云这个梗是什么意思接收验证码手机为什么不能接收验证码
购买域名和空间 阿里云搜索 80vps linkcloud lighttpd 12306抢票助手 全能主机 qq数据库 台湾谷歌网址 免费mysql 卡巴斯基官方免费版 空间合租 100mbps ca187 架设邮件服务器 监控服务器 photobucket 买空间网 windowsserver2012r2 winserver2008 更多