C# 程序启动其他进程程序
1 启动一个独立进程,需要用到的命名空间是:using System.Diagnostics; 进程类是 Process ,进程的相关参数信息类是 ProcessStartInfo
2 等待启动的控制台app代码:
using System;
using System.Threading;
namespace ShowConsoleApp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("app start!");
foreach (string item in args)
{
Console.WriteLine(" accept a arg that is {0}", item);
Thread.Sleep(3000);
}
Console.WriteLine("app stop!");
}
}
}
3 启动模式: 并行和串行模式,注意比较代码区别。
using System;
using System.Threading;
using System.Diagnostics;
namespace HDTest
{
class Program
{
static void Main(string[] args)
{
for (int i = 0; i < 2; i++)
{
//并行: 多个同命实例进程一起执行
RunMutilInstanceProcess(i);
//串行,一个进程启动结束后,运行下一个
// WaitSonProcess(i);
Thread.Sleep(2000);
}
Console.ReadLine();
}
static void RunMutilInstanceProcess(int i)
{
string appPath = @"E:\VS2010Code\AppTest\ShowConsoleApp\bin\Debug\ShowConsoleApp.exe";
ProcessStartInfo process = new ProcessStartInfo();
process.FileName = appPath;
process.Arguments = "process " + i.ToString();
process.UseShellExecute = false;
process.CreateNoWindow = true;
process.RedirectStandardOutput = true;
Process.Start(process);
// string Result = p.StandardOutput.ReadToEnd();
// Console.WriteLine("the console app output is {0}", Result);
Console.WriteLine(" process {0} start", i);
}
static void WaitSonProcess(int i)
{
Process process = new Process();
string appPath = @"E:\VS2010Code\AppTest\ShowConsoleApp\bin\Debug\ShowConsoleApp.exe";
process.StartInfo.FileName = appPath;
process.StartInfo.Arguments = "process " + i.ToString();
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;
// process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
// Start the process
process.Start();
Console.WriteLine(" process {0} start", i);
// Wait that the process exits
process.WaitForExit();
Console.WriteLine("the process had exits");
// Now read the output of the DOS application
string Result = process.StandardOutput.ReadToEnd();
Console.WriteLine("the console app output is {0}", Result);
}
}
}
C# 程序启动其他进程程序的更多相关文章
- 比较windows phone程序启动和android程序启动原理
windows phone 程序是如何启动的了,他和android程序有什么区别,我们重点从native code 层面来分析 在windows phone 程序启动的时候是: 在XAML中使用应用程 ...
- windows phone 8 新增功能:从一个应用程序启动另一个程序(file association 和 Protocol association两种方式)
一. 启动手机预装内置程序打开文件file association 这里以打开word文档为例子 string fileToLaunch = @"HelloKitty.docx"; ...
- IOS在一个程序中启动另一个程序
尽管iPhone不允许同时运行两个应用程序,我们可以从自己的应用程序中启动另一个应用程序,并且可以在应用程序之间共享数据.我们可以使用UIApplication类的openURL:方法从一个应用程序来 ...
- iOS -程序启动原理和UIApplication的介绍
一.UIApplication 简介 (1)UIApplication对象是应用程序的象征,一个UIApplication对象就代表一个应用程序. (2)每一个Application都有自 ...
- 文盘Rust -- 把程序作为守护进程启动
当我们写完一个服务端程序,需要上线部署的时候,或多或少都会和操作系统的守护进程打交道,毕竟谁也不希望shell关闭既停服.今天我们就来聊聊这个事儿. 最早大家部署应用的通常操作是 "nohu ...
- iOS程序启动过程
First, the function creates the main application object (step 3 in the flowchart). If you specify ni ...
- 【Android】应用程序启动过程源码分析
在Android系统中,应用程序是由Activity组成的,因此,应用程序的启动过程实际上就是应用程序中的默认Activity的启动过程,本文将详细分析应用程序框架层的源代码,了解Android应用程 ...
- iOS程序启动的过程及原理
iOS程序启动的过程及原理 文字部分 先执行main函数,main内部会调用UIApplicationMain函数 UIApplicationMain函数里面做了什么事情??? 1> 创建UIA ...
- Qt程序启动画面播放(gif与swf两种动画格式)
学习Qt有一段时间了,发现一个小问题,网上关于Qt的资料或者总结性的学习及应用文章有点少. 比如,Qt完整的API,程序运行之前的启动画面如何按理想效果播放等,每次想在项目中添加一些应用的时候,总是找 ...
随机推荐
- FontAwesome 图标 class="fa fa-home"
本文转自:http://www.yeahzan.com/fa/facss.html 引用方式: class="fa fa-home" 注意:每个图标的引用都必须要添加 fa fa- ...
- bootstrap-fileinput参数
<link rel="stylesheet" href="css/bootstrapCSS/bootstrap.min.css"> <link ...
- Javascript 简单实现鼠标拖动DIV
http://zhangbo-peipei-163-com.iteye.com/blog/1740078 比较精简的Javascript拖动效果函数代码 http://www.jb51.net/art ...
- tomcat server 报错之 More than the maximum allowed number of cookies
More than the maximum allowed number of cookies EVERE: Error processing request java.lang.IllegalArg ...
- 转-vs2017安装并且安装包不占用C盘空间
平常的安装方式,不论是在线安装还是下载的离线安装包,都会在安装过程中将vs2017的安装包保存在C:\ProgramData\Microsoft\VisualStudio\Packages文件夹下并占 ...
- Nodejs 如何制作命令行工具
# 全局安装,安装报错是需要前面加上sudo $ sudo npm install -g xxxb # 输出帮助 $ xxxb -h Usage: xxxb 这里是我私人玩耍的命令哦![options ...
- overflow:hidden的用法
overflow:hidden是大家常用到的CSS样式,但是大多数人对这个样式的理解仅仅局限于隐藏溢出,而对于清除浮动这个含义不是很了解. <%@ Page Language="C#& ...
- Stage4--Python面向对象
说在前面: Stage1-Stage4简单介绍一下Python语法,Stage5开始用python实现一些实际应用,语法的东西到处可以查看到,学习一门程序语言的最终目的是应用,而不是学习语法,语法本事 ...
- Java使用imageio、awt生成图片验证码
1.生成验证码工具类 public class CheckCodeTool { private Integer width = 80; private Integer height = 38; pub ...
- haproxy/nginx+keepalived负载均衡 双机热备 邮件报警 实战及常见问题
Haproxy 做http和tcp反向代理和负载均衡keepalived 为两台 Haproxy 服务器做高可用/主备切换.nginx 为内网服务器做正向代理,如果业务需求有变化,也可以部分替代 ...