• 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.的更多相关文章

  1. [转]Publishing and Running ASP.NET Core Applications with IIS

    本文转自:https://weblog.west-wind.com/posts/2016/Jun/06/Publishing-and-Running-ASPNET-Core-Applications- ...

  2. Console Event Handling

    http://www.codeproject.com/Articles/2357/Console-Event-Handling Console Event Handling Kumar Gaurav ...

  3. Async All the Way

    Asynchronous code reminds me of the story of a fellow who mentioned that the world was suspended in ...

  4. 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# ...

  5. Async/Await - Best Practices in Asynchronous Programming

    https://msdn.microsoft.com/en-us/magazine/jj991977.aspx Figure 1 Summary of Asynchronous Programming ...

  6. 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 ...

  7. Git for Windows v2.11.0 Release Notes

    homepage faq contribute bugs questions Git for Windows v2.11.0 Release Notes Latest update: December ...

  8. 小心C# 5.0 中的await and async模式造成的死锁

    平时在使用C# 5.0中的await and async关键字的时候总是没注意,直到今天在调试一个ASP.NET项目时,发现在调用一个声明为async的方法后,程序老是莫名其妙的被卡住,就算声明为as ...

  9. 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 ...

随机推荐

  1. MFC中改变控件的大小和位置

    用CWnd类的函数MoveWindow()或SetWindowPos()可以改变控件的大小和位置. void MoveWindow(int x,int y,int nWidth,int nHeight ...

  2. 路由器之VPN应用与配置指南

    应用背景 近日,公司需要在外人员通过直接访问连接到公司内网,实现办公等一系列操作,这个时候就需要通过配置路由器VPN实现该需求了. 无线企业路由器可以帮助中小型企业搭建高性价比.稳定的企业办公网络,灵 ...

  3. C# tostring 格式化输出 (转)

    C 货币 2.5.ToString("C") ¥2.50 D 十进制数 25.ToString("D5") 00025 E 科学型 25000.ToString ...

  4. tcpServer 浅显的发一代码

    接下来发出来的一段代码也是我从网上找的一个例子,具体的来源已经找不到了,跟作者说声抱歉 ,现在公司做机票,出于性能的原因,就重写一个底层的tcp请求(不是我写的) 下面测试的是个控制台应用程序 Htt ...

  5. VxWorks 6.9 内核编程指导之读书笔记 -- VxWorks kernel application (一)

    #1 什么是内核应用程序? #2 开发内核应用程序注意事项 什么是内核应用程序? 内核应用程序不同于RTP程序,它允许在内核态,与操作系统使用相同的地址空间.因此,它与操作系统会相互干扰.它可以编译成 ...

  6. onclick和onblur的冲突问题

    新浪首页的搜索框里面有一个使用ajax的下拉框.我们需要实现一个点击下拉框里面的一项,让搜索框里面的值变成这一项,同时下拉框消失的效果,但同时在点击其他地方的时候,这个下拉框也要消失.大致如图: 我们 ...

  7. Shell指令

    Shell指令 1.Shell原理图 2.Shell指令的基本语法 Shell指令 Shell –选项 参数 Shell –选项 Shell参数 3.常用的Shell指令 1)ls指令:显示文件信息 ...

  8. 《HTML5与CSS3基础教程》学习笔记 ——Two Day

    第七章 1.  样式表:选择器和生命块 2.  !important: 某条声明的重要程度比其他高,在末尾添加 3.  属性值:inherit;  是强制继承 4.  1em=16px; 5.  可以 ...

  9. JAVA作业-1

    编写一个程序,用户输入两个数,求出其加减乘除,并用消息框显示计算结果. import javax.swing.JOptionPane; // import class JOptionPane publ ...

  10. Ant打jar包指定MainClass

    一般用ant打jar的时候不用指定程序的入口!这个jar一般是给其他app引用的. 但是如果该jar就是程序的启动jar.例如: java -jar abc.jar  这个时候需要指定jar的入口类! ...