How to avoid C# console applications from closing automatically.
One way is to interop it with msvcrt.dll
You can pinvoke this C function into your C# application. This process is very easy. There are a few steps:1) Insert System.Runtime.InteropServices to your using clauses.
2) Insert this line in your class (usually in the first few lines)[DllImport("msvcrt.dll")]
static extern bool system(string str);3) In that same class, simply write this:
system("pause");
The simplest way that I always use is to ask for input
Console.ReadLine();
or
Console.ReadKey();
ReadLine() waits for ↩, ReadKey() waits for any key (except for modifier keys).
How to avoid C# console applications from closing automatically.的更多相关文章
- [转]Publishing and Running ASP.NET Core Applications with IIS
本文转自:https://weblog.west-wind.com/posts/2016/Jun/06/Publishing-and-Running-ASPNET-Core-Applications- ...
- Console Event Handling
http://www.codeproject.com/Articles/2357/Console-Event-Handling Console Event Handling Kumar Gaurav ...
- Async All the Way
Asynchronous code reminds me of the story of a fellow who mentioned that the world was suspended in ...
- The week in .NET - 1/12/2015
On.NET Last week, we had Mads Torgersen on the show to talk about language design in general, and C# ...
- Async/Await - Best Practices in Asynchronous Programming
https://msdn.microsoft.com/en-us/magazine/jj991977.aspx Figure 1 Summary of Asynchronous Programming ...
- Don't Block on Async Code【转】
http://blog.stephencleary.com/2012/07/dont-block-on-async-code.html This is a problem that is brough ...
- Git for Windows v2.11.0 Release Notes
homepage faq contribute bugs questions Git for Windows v2.11.0 Release Notes Latest update: December ...
- 小心C# 5.0 中的await and async模式造成的死锁
平时在使用C# 5.0中的await and async关键字的时候总是没注意,直到今天在调试一个ASP.NET项目时,发现在调用一个声明为async的方法后,程序老是莫名其妙的被卡住,就算声明为as ...
- Async/Await - Best Practices in Asynchronous Programming z
These days there’s a wealth of information about the new async and await support in the Microsoft .N ...
随机推荐
- 安卓、java开发软件官网和相关不错的网站软件下载地址
java:http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html eclipse:htt ...
- dropdownlist值改变时调用js
DropDownList的OnSelectedIndexChanged方法是服务器端方法如要用需要设置AutoPostBack选项为true,并且在服务器后台写方法 要调用js方法需要onchange ...
- C#颜色 转换
C#Winform 使用16进制颜色 var color = ColorTranslator.FromHtml("#eeeeee");
- 开放-封闭原则(OCP)
对于僵化性的臭味,应用OCP原则之后,再进行同样的改动时,只需添加新代码,而不必改动已正常运行的代码. 扩展模块行为的方式通常是修改模块的Code,不允许修改的模块常常被认为是具有固定的行为. Ope ...
- eclipse下的Tomcat安装与web项目 搭建
Tomcat 安装 环境: win10-64位 apache-tomcat-7.0.57-windows-x64 首先要配置Windows 的环境变量 JAVA_HOME(就是Java的环境变量) ...
- 采用Service实现本地推送通知
在android的应用层中,涉及到很多应用框架,例如:Service框架,Activity管理机制,Broadcast机制,对话框框架,标题栏框架,状态栏框架,通知机制,ActionBar框架等等. ...
- 添加远程链接MySQL的权限
mysql> grant 权限1,权限2,…权限n on 数据库名称.表名称 to 用户名@用户地址 identified by ‘连接口令’; 权限1,权限2,…权限n代表select,ins ...
- Silverlight独立存储
写 private void Button_Click_1(object sender, RoutedEventArgs e) { IsolatedStorageFile isf = Isolated ...
- php中json_encode中文编码问题分析
众所周知使用json_encode可以方便快捷地将对象进行json编码,但是如果对象的属性中存在着中文,问题也就随之而来了.json_encode会将中文转换为unicode编码例如:'胥'经过jso ...
- Vim一些实用的用法
打开多个文件: 1.vim还没有启动的时候:在终端里输入 vim file1 file2 ... filen便可以打开所有想要打开的文件2.vim已经启动输入:open file可以再打开一个文件,并 ...