Make the console wait for a user input to close
In Java this would be System.in.read()
In Java this would be System.in.read()
Environment.Exit and Application.Exit Environment.Exit(0) is cleaner. http://geekswithblogs.net/mtreadwell/archive/2004/06/06/6123.aspx
This is how we do it in our .netcore console app. The key here is to include the right dependencies on your project namely (may be not all, check based on your needs) and copy to output the appSetting.json as part of your buildoptions { “buildOptions”: { “emitEntryPoint”: true, “copyToOutput”: { “include”: [ “appsettings*.json”, “App*.config” … Read more
To get the directory where the .exe file is: AppDomain.CurrentDomain.BaseDirectory To get the current directory: Environment.CurrentDirectory
The error message itself actually details the correct fix: configSections must be the first child* of the root element: *emphasis added So just move the configSections to the top: <configuration> <configSections> <section name=”Reva.Properties.Settings” type=”System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″ requirePermission=”false” /> <section name=”log4net” type=”log4net.Config.Log4NetConfigurationSectionHandler, log4net” /> </configSections> <startup useLegacyV2RuntimeActivationPolicy=”true”> <supportedRuntime version=”v4.0″/> </startup> </configuration>
You can use the ProcessExit event of the AppDomain: class Program { static void Main(string[] args) { AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit); // do some work } static void CurrentDomain_ProcessExit(object sender, EventArgs e) { Console.WriteLine(“exit”); } } Update Here is a full example program with an empty “message pump” running on a separate thread, that allows … Read more
So i came across with this solution, inspired by the accepted answer: Program.cs public class Program { public static void Main(string[] args) { IServiceCollection services = new ServiceCollection(); // Startup.cs finally 🙂 Startup startup = new Startup(); startup.ConfigureServices(services); IServiceProvider serviceProvider = services.BuildServiceProvider(); //configure console logging serviceProvider .GetService<ILoggerFactory>() .AddConsole(LogLevel.Debug); var logger = serviceProvider.GetService<ILoggerFactory>() .CreateLogger<Program>(); logger.LogDebug(“Logger is … Read more
Lanterna I found the Lanterna library recently. Haven’t had the opportunity to use it yet but it looks like a more up-to-date alternative to the others.
For pure C++ You can’t. C++ doesn’t even have the concept of a console. The program could be printing to a printer, outputting straight to a file, or being redirected to the input of another program for all it cares. Even if you could clear the console in C++, it would make those cases significantly … Read more
Change the output type from Console Application to Windows Application. This can be done under Project -> Properties -> Application in Visual Studio: