console-application

How to display list items on console window in C#

隐身守侯 提交于 2019-11-27 12:03:09
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? Svish 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.WriteLine(int) : var list = new List<int>(Enumerable.Range(0, 50)); list.ForEach(Console.WriteLine);

Run console application from other console app

拟墨画扇 提交于 2019-11-27 12:03:05
I have a C# console application (A). I want to execute other console app (B) from within app A (in synchronous manner) in such way that B uses the same command window. When B exists, A should be able to read B's exit code. How to do that? I need only this little tip on how to run this other app in same cmd window. You can use Process.Start to start the other console application. You will need to construct the process with ProcessStartInfo.RedirectOutput set to true and UseShellExecute set to false in order to be able to utilize the output yourself. You can then read the output using

windows form .. console.writeline() where is console?

懵懂的女人 提交于 2019-11-27 11:28:16
问题 I created a windows form solution and in the constructor of a class I called Console.WriteLine("constructer called") But I only got the form and not the console.. so where is the output? 回答1: In project settings set application type as Console. Then you will get console window and Windows form. 回答2: You should also consider using Debug.WriteLine, that's probably what you're looking for. These statements are written out the trace listeners for your application, and can be viewed in the Output

Make the console wait for a user input to close

北慕城南 提交于 2019-11-27 11:24:45
I have a console application that after performing its tasks, must give feedback to the user, such as "operation completed" or "operation failed" and the detailed error. The thing is, if I just "let it run", the output message will be printed but the console will close shortly afterwards, leaving no time to read the message. As far as I remember, in C++, every console application will end with a "press any key to exit" or something like that. In C# I can simulate this behavior with a Console.ReadKey(); But how can I do it in Java? I'm using the Scanner class, but given that "input" is my

Use custom console for Visual Studio Console Application Debugging

萝らか妹 提交于 2019-11-27 09:58:14
问题 Is it possible to set Visual Studio to use a non-standard console when debugging a Console Application? I'm not sure what the default console is, it looks just like cmd.exe . I would really love my Console Application to run in ConEmu when I debug. To be clear, I want to click "Start Debugging" and the process should happen exactly as usual, but instead of bringing up a cmd.exe console, it should bring up a ConEmu console (or whatever). I'm using Visual Studio 2010 Pro Closely related to this

.NET Console TextWriter that Understands Indent/Unindent/IndentLevel

妖精的绣舞 提交于 2019-11-27 09:31:50
Does anybody have or know of a TextWriter for the Console that understand how to indent/unindent and has the ability to set the indent level. Try this: class MyConsole : TextWriter { TextWriter mOldConsole; bool mDoIndent; public MyConsole() { mOldConsole = Console.Out; Console.SetOut(this); } public int Indent { get; set; } public override void Write(char ch) { if (mDoIndent) { mDoIndent = false; for (int ix = 0; ix < Indent; ++ix) mOldConsole.Write(" "); } mOldConsole.Write(ch); if (ch == '\n') mDoIndent = true; } public override System.Text.Encoding Encoding { get { return mOldConsole

CPU friendly infinite loop

自古美人都是妖i 提交于 2019-11-27 09:24:25
问题 Writing an infinite loop is simple: while(true){ //add whatever break condition here } But this will trash the CPU performance. This execution thread will take as much as possible from CPU's power. What is the best way to lower the impact on CPU? Adding some Thread.Sleep(n) should do the trick, but setting a high timeout value for Sleep() method may indicate an unresponsive application to the operating system. Let's say I need to perform a task each minute or so in a console app. I need to

Hide Console Window in C# Console Application

泪湿孤枕 提交于 2019-11-27 09:22:37
问题 The thing is, i really dont want the console window to show up...but the solution should be running. My point here is, I want to keep the application running in the background, without any window coming up. 回答1: Change the output type from Console Application to Windows Application . This can be done under Project -> Properties -> Application in Visual Studio: 回答2: Change your application type to a windows application. Your code will still run, but it will have no console window, nor standard

Console.Read() and Console.ReadLine() problems

老子叫甜甜 提交于 2019-11-27 09:19:58
I have been trying to use Console.Read() and Console.ReadLine() in C# but have been getting weird results. for example this code Console.WriteLine("How many students would you like to enter?"); int amount = Console.Read(); Console.WriteLine("{0} {1}", "amount equals", amount); for (int i=0; i < amount; i++) { Console.WriteLine("Input the name of a student"); String StudentName = Console.ReadLine(); Console.WriteLine("the Students name is " + StudentName); } has been giving me that amount = 49 when I input 1 for the number of students, and Im not even getting a chance to input a student name.

Owin Self host & ASP .Net MVC

为君一笑 提交于 2019-11-27 09:02:32
I have an ASP .Net MVC app which works just fine under IIS. I need to be able to run the same app from a self hosted console app. How do I do that? Should I use OWIN? What the code should look like? Update Now that ASP.NET Core is out there are a few ways to Self Host a web application. One option is to use an OWIN based web server such as Nowin . var host = new WebHostBuilder() .UseNowin() .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup<Startup>() .Build(); Alternatively, Kestrel has also been a popular choice for hosting ASP.NET Core applications. var host = new WebHostBuilder()