console-application

Show message Box in .net console application

拟墨画扇 提交于 2019-12-18 03:57:18
问题 How to show a message box in a .net c# or vb console application ? Something like: Console.WriteLine("Hello World"); MessageBox.Show("Hello World"); or Console.WriteLine("Hello") MsgBox("Hello") in c# and vb respectively. Is it possible? 回答1: We can show a message box in a console application. But first include this reference in your vb.net or c# console application System.Windows.Forms; Reference: To add reference in vb.net program right click (in solution explorer) on your project name->

C# Console Application - Keep it running

风格不统一 提交于 2019-12-18 03:22:14
问题 I am about to develop a console application that will be required to continually run and carry out work at specific times. My question is what is are best methods or practices to keep your application alive? My thought were: A loop that never ends? A timer that sleeps and then jumps to routine when required (after set sleep period)? I will be compiling the application into an exe and then running it as a service using AlwaysUp. Regards.. Peter 回答1: A better solution would be to write a

Re-Open WPF Window from a Console application

僤鯓⒐⒋嵵緔 提交于 2019-12-17 20:59:20
问题 I want to open a WPF Window from a Console application. After referring to this post, it works fine. The problem is: When the user closed the WPF Window (manually), it can no long be re-opened from the Console, throwing the exception message: "Cannot create more than one System.Windows.Application instance in the same AppDomain." Here is the code: class Program { static void Main(string[] args) { string input=null; while ((input = Console.ReadLine()) == "y") { //Works fine at the first

Calling a console app from the command line with string[] args

安稳与你 提交于 2019-12-17 20:54:17
问题 I have a .NET Console app (very simple). The entry point takes the infamous string[] args argument. Does this mean that from a command line, I could call this app and pass in a single string as a parameter? If so, how? 回答1: Yes, the string[] args is from the command line. The zeroth element is the first argument and so on. Please note unlike C or C++, args[0] doesn't contain the application name. So if you do: application.exe arg1 arg2 arg3 Then: args[0] = arg1 args[1] = arg2 args[2] = arg3

How to set default input value in .Net Console App?

 ̄綄美尐妖づ 提交于 2019-12-17 20:44:24
问题 How can you set a default input value in a .net console app? Here is some make-believe code: Console.Write("Enter weekly cost: "); string input = Console.ReadLine("135"); // 135 is the default. The user can change or press enter to accept decimal weeklyCost = decimal.Parse(input); Of course, I don't expect it to be this simple. I am betting on having to do some low-level, unmanaged stuff; I just don't know how. EDIT I know I can replace no input with the default. That's not what I am asking

When writing carriage return to a pycharm console the whole line is deleted?

吃可爱长大的小学妹 提交于 2019-12-17 20:39:05
问题 I have a program in Python that makes extensive use of the line feed character to produce the effect of an updating console line (specifically a progress bar). When trying to debug the code in PyCharm I saw that the progress bar doesn't get printed until it's done. Upon further inspection it turned out that when a carriage return ( \r ) is printed, the whole line is deleted. Because the library itself writes strings of the form ( {line}\r ), I always get an empty line. Is there any way to

how to execute console application from windows form?

萝らか妹 提交于 2019-12-17 18:37:54
问题 I want to run a console application (eg app.exe) from a windows form load event. I'v tried System.Diagnostics.Process.Start(), But after it opens app.exe, it closes it immidiately. Is there any way that I can run app.exe and leave it open? 回答1: If you are just wanting the console window to stay open, you could run it with something like this command: System.Diagnostics.Process.Start( @"cmd.exe", @"/k c:\path\my.exe" ); 回答2: Try doing this: string cmdexePath = @"C:\Windows\System32\cmd.exe"; /

How to enforce required command-line options with NDesk.Options?

£可爱£侵袭症+ 提交于 2019-12-17 18:25:40
问题 I was just writing a console utility and decided to use NDesk.Options for command-line parsing. My question is, How do I enforce required command-line options? I see in the docs that: options with a required value (append '=' to the option name) or an optional value (append ':' to the option name). However, when I put a = at the end of the option name there is no difference in behavior. Ideally the Parse method would throw an exception. Is there something else I need to do? Here is my test

How to add AutoMapper to DI in .Net core 2.0 Console Application

邮差的信 提交于 2019-12-17 17:14:17
问题 I try to use AutoMapper in my .Net Core 2.0 Console Application. My class looks like this: public class AutoGetCurrency { private readonly IMapper mapper; public AutoGetCurrency(IMapper mapper) { this.mapper = mapper; } .... } I tried to add services into Main method: static void Main(string[] args) { var services = new ServiceCollection(); ServiceProvider = services.BuildServiceProvider(); services.AddTransient<IMapper>(); .... } But I have the next error 'One or more errors occurred.

How to hide a console application in C#

蹲街弑〆低调 提交于 2019-12-17 16:32:52
问题 I have a console application in C#, and I want that the user won't be able to see it. How can I do that? 回答1: Compile it as a Windows Forms application. Then it won't display any UI, if you do not explicitly open any Windows. 回答2: On ProjectProperties set Output Type as Windows Application. 回答3: Sounds like you don't want a console application, but a windows GUI application that doesn't open a (visible) window. 回答4: Create a console application "MyAppProxy" with following code, and put