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# 程序启动其他进程程序的更多相关文章

  1. 比较windows phone程序启动和android程序启动原理

    windows phone 程序是如何启动的了,他和android程序有什么区别,我们重点从native code 层面来分析 在windows phone 程序启动的时候是: 在XAML中使用应用程 ...

  2. windows phone 8 新增功能:从一个应用程序启动另一个程序(file association 和 Protocol association两种方式)

    一. 启动手机预装内置程序打开文件file association 这里以打开word文档为例子 string fileToLaunch = @"HelloKitty.docx"; ...

  3. IOS在一个程序中启动另一个程序

    尽管iPhone不允许同时运行两个应用程序,我们可以从自己的应用程序中启动另一个应用程序,并且可以在应用程序之间共享数据.我们可以使用UIApplication类的openURL:方法从一个应用程序来 ...

  4. iOS -程序启动原理和UIApplication的介绍

    一.UIApplication 简介       (1)UIApplication对象是应用程序的象征,一个UIApplication对象就代表一个应用程序. (2)每一个Application都有自 ...

  5. 文盘Rust -- 把程序作为守护进程启动

    当我们写完一个服务端程序,需要上线部署的时候,或多或少都会和操作系统的守护进程打交道,毕竟谁也不希望shell关闭既停服.今天我们就来聊聊这个事儿. 最早大家部署应用的通常操作是 "nohu ...

  6. iOS程序启动过程

    First, the function creates the main application object (step 3 in the flowchart). If you specify ni ...

  7. 【Android】应用程序启动过程源码分析

    在Android系统中,应用程序是由Activity组成的,因此,应用程序的启动过程实际上就是应用程序中的默认Activity的启动过程,本文将详细分析应用程序框架层的源代码,了解Android应用程 ...

  8. iOS程序启动的过程及原理

    iOS程序启动的过程及原理 文字部分 先执行main函数,main内部会调用UIApplicationMain函数 UIApplicationMain函数里面做了什么事情??? 1> 创建UIA ...

  9. Qt程序启动画面播放(gif与swf两种动画格式)

    学习Qt有一段时间了,发现一个小问题,网上关于Qt的资料或者总结性的学习及应用文章有点少. 比如,Qt完整的API,程序运行之前的启动画面如何按理想效果播放等,每次想在项目中添加一些应用的时候,总是找 ...

随机推荐

  1. JVM 类加载全过程

    类加载机制 - JVM把class文件加载到内存中 并对数据进行 校验,解析,初始化,最终形成JVM可以直接使用的java类型的过程 详细过程  加载→ 验证→ 准备→ 解析 → 初始化→ 使用 → ...

  2. [转]ASP.NET Core 中文文档 第四章 MVC(4.3)过滤器

    本文转自:http://www.cnblogs.com/dotNETCoreSG/p/aspnetcore-4_4_3-filters.html 原文:Filters 作者:Steve Smith 翻 ...

  3. 世界、国家、省、城市SQL

    共享一份 世界.国家.省.城市最全的SQL(mysql可直接使用),笔者是花了下载币下载的 下载SQL #  pid=0 获取所有国家 #  pid=99999999    获取中国的省.自治区.直辖 ...

  4. 2017年10月21日 数据库基础&三大范式

    1. 数据库里面常用 int        整型nvarchar   字符串float       小数型decimal(,) 小数型money      小数型datetime   时间类型 ima ...

  5. HDU 5012 骰子旋转(DFS)

    http://acm.hdu.edu.cn/showproblem.php?pid=5012 保存骰子的状态,然后用dfs或者bfs搜索 还是再讲一下dfs 我们的目标是找一个与b相同,且转次数最少的 ...

  6. Csharp:TinyMCE HTML Editor in .NET WindowsForms

    /// <summary> /// /// </summary> public partial class Form2 : Form { private mshtml.IHTM ...

  7. Django组件——forms组件

    一.校验字段功能 通过注册用户这个实例来学习校验字段功能. 1.模型:models.py from django.db import models # Create your models here. ...

  8. caffe-windows中classification.cpp的源码阅读

    caffe-windows中classification.cpp的源码阅读 命令格式: usage: classification string(模型描述文件net.prototxt) string( ...

  9. Angular JS例子 ng-repeat遍历输出

    首先要有Angular的插件:然后才开始遍历 :<!DOCTYPE html> <html lang="en"> <head> <meta ...

  10. libcurl 中使用curl_multi_perform()函数执行订阅类型url的问题

    前提概要 当需要同时处理多个url时,可采用curl_multi_perform方式执行,如下代码1: //初始化一个multi curl 对象 CURLM * curl_m = curl_multi ...