console-application

How to run a C# console application with the console hidden

雨燕双飞 提交于 2019-11-26 11:35:28
Is there a way to hide the console window when executing a console application? I am currently using a Windows Forms application to start a console process, but I don't want the console window to be displayed while the task is running. Adam Markowitz If you are using the ProcessStartInfo class you can set the window style to hidden - in the case of console (not GUI) applications, you have to set CreateNoWindow to true : System.Diagnostics.ProcessStartInfo start = new System.Diagnostics.ProcessStartInfo(); start.FileName = dir + @"\Myprocesstostart.exe"; start.WindowStyle = System.Diagnostics

How to handle key press events in c++

故事扮演 提交于 2019-11-26 11:29:15
问题 I am writing a custom console program. And I want to make it look like an actual one. So I want to bind some actions with keypress events. For example when the up arrow is pressed previously executed commands should be shown to the user. I know about SDL. But I think that it\'s not a standard library, is it ?? If there is other alternative of it, that included in standard CPP library, please let me know. Thanks. 回答1: You won't find anything in the standard library for that. It's all Platform

Command to close an application of console?

狂风中的少年 提交于 2019-11-26 10:49:02
问题 I need to close the console when the user selects a menu option. I tried using close() but it did not work.. how can I do this? 回答1: Environment.Exit and Application.Exit Environment.Exit(0) is cleaner. http://geekswithblogs.net/mtreadwell/archive/2004/06/06/6123.aspx 回答2: By close, do you mean you want the current instance of the console app to close, or do you want the application process, to terminate? Missed that all important exit code: Environment.Exit(0); Or to close the current

How to display list items on console window in C#

青春壹個敷衍的年華 提交于 2019-11-26 10:32:42
问题 I have a List which contains all databases names. I have to dispaly the items contained in that list in the Console (using Console.WriteLine() ). How can I achieve this? 回答1: Actually you can do it pretty simple, since the list have a ForEach method and since you can pass in Console.WriteLine as a method group. The compiler will then use an implicit conversion to convert the method group to, in this case, an Action<int> and pick the most specific method from the group, in this case Console

Hide console window from Process.Start C#

倾然丶 夕夏残阳落幕 提交于 2019-11-26 10:24:19
I am trying to create process on a remote machine using using System.Diagnostics.Process class. I am able to create a process. But the problem is, creating a service is take a long time and console window is displayed. Another annoying thing is the console window is displayed on top of my windows form and i cant do any other operations on that form. I have set all properties like CreateNoWindow = true , proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden but still it shows the console window. even i have redirected output and errors to seperate stream but no luck. Is there any other way to

What is the command to exit a Console application in C#?

隐身守侯 提交于 2019-11-26 10:14:59
问题 What is the command in C# for exit a Console Application? 回答1: You can use Environment.Exit(0); and Application.Exit Environment.Exit(0) is cleaner. 回答2: Several options, by order of most appropriate way: Return an int from the Program.Main method Throw an exception and don't handle it anywhere (use for unexpected error situations) To force termination elsewhere, System.Environment.Exit ( not portable! see below ) Edited 9/2013 to improve readability Returning with a specific exit code: As

Is there a way to make a console application run using only a single file in .NET Core?

↘锁芯ラ 提交于 2019-11-26 09:58:29
问题 In .NET framework, you can make a single .EXE file that will run from the command line without having any extra config files (and if using ILMerge, you can put all .DLL references into the 1 .EXE assembly). I am taking a stab at using .NET Core to accomplish the same thing, but so far without success. Even the simplest Hello World application with no dependencies requires there to be a file named <MyApp>.runtimeconfig.json in order to run using dotnet.exe . dotnet F:\\temp\\MyApp.dll The

C# arrow key input for a console app

你。 提交于 2019-11-26 09:13:18
问题 I have a simple console app written in C#. I want to be able to detect arrow key presses, so I can allow the user to steer. How do I detect keydown/keyup events with a console app? All my googling has led to info about windows Forms. I don\'t have a GUI. This is a console app (to control a robot over a serial port). I have functions written to handle these events, but I have no idea how to register to actually receive the events: private void myKeyDown(object sender, KeyEventArgs e) { switch

Download multiple files async and wait for all of them to finish before executing the rest of the code

耗尽温柔 提交于 2019-11-26 09:10:05
问题 I am trying to download multiple files from the internet and await for all of them to finish. This is a C# console application that I am running, so no progress bar event handler should be necessary. However it currently just continues to execute code even though all files have not been downloaded. 1.Downloading all files! 2.Finished Download File A 3.Finished Downloading all files! 4.Finished Downloading File B 5.Finished Downloading File C How would you await till all async download files

Why does closing a console that was started with AllocConsole cause my whole application to exit? Can I change this behavior?

耗尽温柔 提交于 2019-11-26 08:56:01
问题 What I want to have happen is that the console window just goes away, or better yet that it is hidden, but I want my application to keep running. Is that possible? I want to be able to use Console.WriteLine and have the console serve as an output window. I want to be able to hide and show it, and I don\'t want the whole app to die just because the console was closed. EDIT Code: internal class SomeClass { [DllImport(\"kernel32\")] private static extern bool AllocConsole(); private static void