在应用程序结束后如何保持简单的c#控制台应用程序运行。 [英] how to keep a simple c# console app running after end of the application.

查看:386
本文介绍了在应用程序结束后如何保持简单的c#控制台应用程序运行。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用c#编写的简单控制台工具。一旦用户通过键入并按Enter键输入一些数据。我的工具可以正常工作,并为用户打印一些有用的信息。由于用户已经按下Enter键,因此即使我将Console.WriteLine();放到控制台应用程序窗口也将关闭。因此,用户无法从控制台应用程序读取输出信息。

I have a simple console tool which is written in c#. As soon as the user enters some data by typing and hitting enter key. My tool does it work and prints out some useful information for the user. Since user already hit the enter key, the console app windows is close even if I put Console.WriteLine(); So the user can't read the output information from the console app.

我添加了Console.WriteLine();两次以保持窗口打开,但是在应用程序结束后立即关闭了该应用程序。当前,唯一的方法是从命令行运行控制台应用程序。当应用程序从命令行完成时。它使控制台保持打开状态,然后用户可以读取应用程序的输出。

I added Console.WriteLine(); two times to keep the windows open, but it closes the app immediately after the end of the application. Currently, the only way is to run the console app from command line. When the app finishes from the command line. It keeps the console open and then the user can read the application output.

但是我想要它,以便用户可以通过双击文件浏览器来打开应用程序。它将完成工作,并为用户保持控制台打开状态。以便用户可以读取输出。然后,他可以通过关闭按钮关闭。

But I want it so that users can open the app by double click from file explorer. It will do it's work and keep the console open for the user. So that the user can read the output. Then he can close by close button.

p.s:请注意,我不需要任何后台运行服务。对我而言,唯一重要的事情是允许用户从应用程序中读取最后的输出消息。

p.s: Note that I don't want any kind of background running service. For me only important matter to allow the user to read the last output message from the application.

推荐答案

只需使用 Console.ReadKey();

Console.Write(yourOutput);
Console.ReadKey();

这篇关于在应用程序结束后如何保持简单的c#控制台应用程序运行。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆