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

发布于 2024-12-06 02:38:09 字数 695 浏览 0 评论 0原文

可能的重复:
在编写控制台应用程序时,有没有办法创建第二个控制台以输出到.NET?

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

Possible Duplicate:
Is there a way to create a second console to output to in .NET when writing a console application?

How to open a new console application (2) while running the existing console app (1)?

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
    }                   
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风尘浪孓 2024-12-13 02:38:10

请参阅 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");
        }
    }
}

See Process Class

System.Diagnostics.Process.Start()

Edit: Something like that, but you have to notice that this will create a new instance of the application every time the previous version closed! (is that what you want?)

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");
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文