【问题标题】:Open a new console application while running the existing console app) [duplicate]在运行现有控制台应用程序时打开一个新的控制台应用程序)[重复]
【发布时间】:2011-09-21 06:22:03
【问题描述】:

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

如何在运行现有控制台应用程序 (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
    }                   
}

【问题讨论】:

  • 您是想启动第二个进程,还是有更多的想法?
  • 只想打开第二个控制台应用程序...

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


【解决方案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");
        }
    }
}

【讨论】:

  • 你能不能详细解释一下...
  • 在这种情况下,它会在启动第二个实例后自动关闭。 p.s.:将System.Diagnostics.Process.Start("ConsoleApplication15.exe"); 放在finally块中不管发生什么都会创建第二个实例,无论如何,你可以在static main方法中使用return;关键字来关闭你的应用程序
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-01-22
  • 1970-01-01
  • 1970-01-01
  • 2019-01-30
  • 1970-01-01
  • 2010-10-05
  • 2010-11-04
相关资源
最近更新 更多