console-application

How do I get a return value from Task.WaitAll() in a console app?

会有一股神秘感。 提交于 2019-11-27 03:43:12
问题 I am using a console app as a proof of concept and new need to get an async return value. I figured out that I need to use Task.WaitAll() in my main method to avoid needing an async "main()" method, which is illegal. I'm now stuck trying to figure out an overload that allows me to use generics or just returns an object that I can cast, but while in Main(). 回答1: You don't get a return value from Task.WaitAll . You only use it to wait for completion of multiple tasks and then get the return

C# Console - hide the input from console window while typing

不想你离开。 提交于 2019-11-27 03:20:22
问题 I'm using Console.ReadLine to read the input of the user. However, I want to hide/exclude the inputted text on the console screen while typing. For example, when the user writes "a", it writes "a" to the console and then I will have a variable with the value "a". However, I don't want "a" to be written on the console's output. How can I do that? 回答1: Here is a short implementation. thx @ojblass for the idea System.Console.Write("password: "); string password = null; while (true) { var key =

C#: Is it possible to have a single application behave as Console or Windows application depending on switches?

ぐ巨炮叔叔 提交于 2019-11-27 02:56:37
问题 I have a simple application that I would like to sort of automate via switches. But when I do run it via switches I don't really want a user interface showing. I just want it to run, do it's job, print stuff out in the console, and exit. On the other hand if I don't run it with any switches I want the user interface to pop up. And in this case I don't really want a console window hanging around in the background. Is there any way I can do this, or do I have to create two separate projects,

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

我怕爱的太早我们不能终老 提交于 2019-11-27 02:54:38
What is the command in C# for exit a Console Application? You can use Environment.Exit(0); and Application.Exit Environment.Exit(0) is cleaner . 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 Servy points out in the comments, you can declare Main with an int return type and return an error code that way.

How to keep console window open

删除回忆录丶 提交于 2019-11-27 02:07:31
When I run my program, the console window seems to run and close. How to keep it open so I can see the results? class Program { public class StringAddString { public virtual void AddString() { var strings2 = new string[] { "1", "2", "3", "4", "5","6", "7", "8", "9"}; Console.WriteLine(strings2); Console.ReadLine(); } } static void Main(string[] args) { StringAddString s = new StringAddString(); } } You forgot calling your method: static void Main(string[] args) { StringAddString s = new StringAddString(); s.AddString(); } it should stop your console, but the result might not be what you

How to programmatic disable C# Console Application's Quick Edit mode?

人走茶凉 提交于 2019-11-27 00:42:59
I,ve tried several solutions found, like the one -> http://www.pcreview.co.uk/forums/console-writeline-hangs-if-user-click-into-console-window-t1412701.html But, i observed that mode in GetConsoleMode(IntPtr hConsoleHandle, out int mode) will be different for different console app. It is not constant. Can I disable mouse clicks (right/left buttons) on a console application to achieve the same scenario. I found that it can be done with IMessageFilter but only for Window Form Application and not for console application. Please guide. If you want to disable quick edit mode, you need to call

Cooler ASCII Spinners? [closed]

一曲冷凌霜 提交于 2019-11-26 23:44:39
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . In a console app, an ascii spinner can be used, like the GUI wait cursor, to indicate that work is being done. A common spinner cycles through these 4 characters: '|', '/', '-', '\' What are some other cyclical animation sequences to spice up a console application? 回答1:

How to determine if GraphicsEnvironment exists

房东的猫 提交于 2019-11-26 23:03:46
问题 I have an application that needs user input for password. What i want to do is to either read the password from console (if the OS supports one e.g unix) or display a JOptionPane and ask the user to enter his password (if the OS supports graphical interface e.g windows). Some people may argue that a console will always be available in both the above cases so a console input will be sufficient. But problem is if the Java app starts using javaw.exe then a console is not available. Thus, i need

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

倾然丶 夕夏残阳落幕 提交于 2019-11-26 22:50:53
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 are finished. private void DownloadMultipleFiles(List<DocumentObject> doclist) { foreach(var value in

How can I copy a string to the clipboard within my console application WITHOUT adding a reference to System.Windows.Forms?

拜拜、爱过 提交于 2019-11-26 22:48:00
问题 I have a .NET 4.0 console application that generates SQL and stores it in a string variable. I want this string to be copied directly to the clipboard. So far, all my research indicates that the ONLY way this can possibly be done is by adding a reference to System.Windows.Forms. I do not want to add a reference to an assembly that is irrelevant to a console application. Within the universe in which we currently exist, is there a known method of copying a string of text to the clipboard within