运行现有控制台应用程序时打开新的控制台应用程序)

时间:2011-09-21 06:22:03

标签: c# .net .net-3.5 console

  

可能重复:
  Is there a way to create a second console to output to in .NET when writing a console application?

如何在运行现有控制台app(1)的同时打开新的控制台应用程序(2)?

static void Main(string[] args)
{
    try
    {
       Console.WriteLine("success"); 

       //how to close this console          
    }
    catch (Exception ex)
    {
        Console.WriteLine("Error Due To: " + ex.Message);
    }
    finally
    {
        //code for opening the second console....(is that passible)
        //how to close this console
    }                   
}

1 个答案:

答案 0 :(得分:1)

请参阅Process班级

System.Diagnostics.Process.Start()

编辑:类似的东西,但你必须注意,每次关闭上一版本时,这将创建应用程序的新实例! (是你想要的吗?

class Program
{
    static void Main(string[] args)
    {
        try
        {
            Console.WriteLine("success");
        }
        catch (Exception ex)
        {
            Console.WriteLine("Error Due To: " + ex.Message);
        }
        finally
        {
            //code for opening the second console....(is that passible)
            System.Diagnostics.Process.Start("ConsoleApplication15.exe");
        }
    }
}