在 C# 控制台应用程序中退出控制台窗口 [英] To exit the console window in C# console application

查看:95
本文介绍了在 C# 控制台应用程序中退出控制台窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的文件写入后端文件夹后立即退出控制台窗口,但无论我尝试什么,

I wanted to exit the console window as soon as my files are written in folder at back end but no matter whatever I try,

Environment.exit(0);
Environment.exit(1);
Environment.exit(-1);

此外,由于我是从 main 方法执行的,因此我正在返回值,即使将文件写入目标文件夹,我的控制台窗口仍然没有关闭,

also since I am executing from main method, I am returning the value, still my console window doesn't go off even after file are written to the destination folder,

下面是我的代码,

 static void Main(string[] args)
    {
        string execute = ""; 
        execute = data_info_pooling(args[0], args[1], args[2]);
         Environment.Exit(0);
    }

我也尝试使用 Application.exit(); 但我无法在下拉框中获取应用程序,我已经探索了几乎所有可能的来自 stackoverflow 的帮助链接并搜索了任何帮助但不知道我哪里出错了,我试图通过打开命令提示符然后执行如下命令来运行此控制台应用程序

Also I tried for using Application.exit(); but I am not able to get Application in drop-down box, I have explored almost all the possible helping links from stackoverflow and searched for any help but no idea where I am going wrong, I am trying to run this console application by opening the command prompt and then executing the command as below

Project Path\Debug>"Project.exe" "第一个参数" "第二个参数" "第三个参数",

在目标文件夹中写入文件后,控制台窗口等待,按回车键后它只是再次提供路径执行但我希望窗口在写入文件的任务完成后立即退出,

After file are written in the destination folder, console window waits and after pressing enter it just gives the path again to execute but I want window to exit as soon as task of writing file is completed,

任何帮助将不胜感激,

-------更新代码--------

-------Update Code--------

我删除了不必要的 for 循环,实际上我在应用逻辑上犯了错误并为我的错误道歉,下面的一些评论帮助我意识到我的错误,终于Environment.exit();

I have deleted for loop which is not necessary, actually I was wrong in application of my logic and apologize for my mistake, some of the below comments helped me to realize my mistake,it's finally Environment.exit();

哪个有效,我也想尝试另一个形成批次的答案.无论如何...感谢大家的宝贵回复.

which works, also I would like to give try to another answer of forming batch. Anyways...Thanks to all for yours valuable replies.

推荐答案

Environment.ExitApplication.Exit

Environment.Exit(0) 更干净.

http://geekswithblogs.net/mtreadwell/archive/2004/06/06/6123.aspx

这篇关于在 C# 控制台应用程序中退出控制台窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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