console-application

How can you determine how a console application was launched?

痴心易碎 提交于 2019-11-29 07:51:18
How can I tell whether the user launched my console application by double-clicking the EXE (or a shortcut), or whether they already had a command line window open and executed my console app within that session? Fowl Stick this static field in your " Program " class to ensure it runs before any output: static bool StartedFromGui = !Console.IsOutputRedirected && !Console.IsInputRedirected && !Console.IsErrorRedirected && Environment.UserInteractive && Environment.CurrentDirectory == System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) && Console.CursorTop == 0

WCF Self Host Service - Endpoints in C#

给你一囗甜甜゛ 提交于 2019-11-29 07:05:46
My first few attempts at creating a self hosted service. Trying to make something up which will accept a query string and return some text but have have a few issues: All the documentation talks about endpoints being created automatically for each base address if they are not found in a config file. This doesn't seem to be the case for me, I get the "Service has zero application endpoints..." exception. Manually specifying a base endpoint as below seems to resolve this: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ServiceModel; using System

Invoke delegate on main thread in console application

与世无争的帅哥 提交于 2019-11-29 04:59:11
In a Windows Application, when multiple threads are used, I know that it’s necessary to invoke the main thread to update GUI components. How is this done in a Console Application? For example, I have two threads, a main and a secondary thread. The secondary thread is always listening for a global hotkey; when it is pressed the secondary thread executes an event that reaches out to the win32 api method AnimateWindow. I am receiving an error because only the main thread is allowed to execute said function. How can I effectively tell the main thread to execute that method, when "Invoke" is not

How do I wait until a console application is idle?

拥有回忆 提交于 2019-11-29 04:22:01
I have a console application that starts up, hosts a bunch of services (long-running startup), and then waits for clients to call into it. I have integration tests that start this console application and make "client" calls. How do I wait for the console application to complete its startup before making the client calls? I want to avoid doing Thread.Sleep(int) because that's dependent on the startup time (which may change) and I waste time if the startup is faster . Process.WaitForInputIdle works only on applications with a UI (and I confirmed that it does throw an exception in this case). I'm

Using Unicode font in C++ console app

感情迁移 提交于 2019-11-29 03:24:04
问题 How do I change the font in my C++ Windows console app? It doesn't seem to use the font cmd.exe uses by default (Lucida Console). When I run my app through an existing cmd.exe (typing name.exe) it looks like this: http://dathui.mine.nu/konsol3.png which is entierly correct. But when I run my app seperatly (double-click the .exe) it looks like this: http://dathui.mine.nu/konsol2.png. Same code, two different looks. So now I wonder how I can change the font so it always looks correctly

Can I get copy/paste functionality from a C# Console Window?

只谈情不闲聊 提交于 2019-11-29 02:49:32
I am developing a console application in C#, and was wondering if there was a way to get the "copy-paste" or "mark-paste" functionality into my application, similar or identical to that of the standard Windows command prompt. Is this a wild goose chase or a simple application variable? Jamie Keeling I've copied text from the Console window and pasted it into another source many times. It's there as default in a Console application; Right click the console border: Select Edit > Mark: Drag over the text you want using the mouse (Or use the arrow keys) to select the text you want: Again, right

C# How to redirect stream to the console Out?

倾然丶 夕夏残阳落幕 提交于 2019-11-29 02:47:46
I found lots of samples how to redirect console output into a file. However I need an opposite solution - I have StreamWriter which I want to be shown in the Console output once I do sw.WriteLine("text"); Just point the stream to standard output: sw = new StreamWriter(Console.OpenStandardOutput()); sw.AutoFlush = true; Console.SetOut(sw); Not that previous answer not correct, but since i do not have enough reputation level to add comment, just adding another answer: If you would ever use pointing Stream to standard output as John proposed with using statement you should not forget to re-open

C# Console Application - Keep it running

删除回忆录丶 提交于 2019-11-29 01:50:33
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 A better solution would be to write a console application that does its job and quits. You can then use the Windows Task Scheduler to run it

C# console app to send email at scheduled times

只愿长相守 提交于 2019-11-29 01:06:24
问题 I've got a C# console app running on Windows Server 2003 whose purpose is to read a table called Notifications and a field called "NotifyDateTime" and send an email when that time is reached. I have it scheduled via Task Scheduler to run hourly, check to see if the NotifyDateTime falls within that hour, and then send the notifications. It seems like because I have the notification date/times in the database that there should be a better way than re-running this thing every hour. Is there a

String calculator [closed]

戏子无情 提交于 2019-11-29 00:36:59
Hi fellow programmers, I am creating a calculator in C# and I have a string variable math which contains 100 * 5 - 2 How can I display its output which is 498 in my console? My code is this: String math = "100 * 5 - 2"; Console.WriteLine(math); Console.ReadLine(); // For Pause So basically, what my code will give me is the string itself which 100 * 5 - 2 but I want it to give me 498 as a result. Idea about this is pretty much appreciated. Thanks Sudhakar Tillapudi Regular Expression evaluation can be done using DataTable.Compute method (from MSDN ) : Computes the given expression on the