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

CloudCone($82/月)15-100M不限流量,洛杉矶CN2 GIA线路服务器

之前分享过很多次CloudCone的信息,主要是VPS主机,其实商家也提供独立服务器租用,同样在洛杉矶MC机房,分为两种线路:普通优化线路及CN2 GIA,今天来分享下商家的CN2 GIA线路独立服务器产品,提供15-100Mbps带宽,不限制流量,可购买额外的DDoS高防IP,最低每月82美元起,支持使用PayPal或者支付宝等付款方式。下面分享几款洛杉矶CN2 GIA线路独立服务器配置信息。配...

妮妮云,美国cera CN2线路,VPS享3折优惠

近期联通CUVIP的线路(AS4837线路)非常火热,妮妮云也推出了这类线路的套餐以及优惠,目前到国内优质线路排行大致如下:电信CN2 GIA>联通AS9929>联通AS4837>电信CN2 GT>普通线路,AS4837线路比起前两的优势就是带宽比较大,相对便宜一些,所以大家才能看到这个线路的带宽都非常高。妮妮云互联目前云服务器开放抽奖活动,每天开通前10台享3折优惠,另外...

远程登录VNC无法连接出现

今天有网友提到自己在Linux服务器中安装VNC桌面的时候安装都没有问题,但是在登录远程的时候居然有出现灰色界面,有三行代码提示"Accept clipboard from viewers,Send clipboard to viewers,Send primary selection to viewers"。即便我们重新登录也不行,这个到底如何解决呢?这里找几个可以解决的可能办法,我们多多尝试。...

useshellexecute为你推荐
域名购买便宜哪买域名比较便宜,我是玩家买不起贵的亚马逊服务器价格亚马逊海外仓收费标准是什么样的?免费服务器资源免费资源赞助 免费赞助服务器 带宽 www.22w.com腾讯云域名绑定服务器怎么把域名绑定到云服务器ECS上华为云服务找回手机我的华为手机刚刚丢了,处于关机状态下可以定位找回吗云服务器可以做什么小米云服务的家人共享能做什么?那好问一首歌:歌词有..........离家的人流浪在远方,没有那好衣裳没有那好烟..........dc4电脑中ASCLL码是 指什么?好看的表格样式创意如何使用PS快速制作美观的表格ms min计算机中的latency是什么意思?
免费网站域名申请 万网域名查询 长沙服务器租用 双线vps 账号泄露 NetSpeeder 云图标 500m空间 华为4核 ftp教程 免费个人空间 佛山高防服务器 电信主机 东莞服务器 海外空间 dnspod 阿里云邮箱申请 阿里云个人邮箱 hdroad vim 更多