console-application

How to cancel Task await after a timeout period

半城伤御伤魂 提交于 2019-11-26 01:19:39
问题 I am using this method to instantiate a web browser programmatically, navigate to a url and return a result when the document has completed. How would I be able to stop the Task and have GetFinalUrl() return null if the document takes more than 5 seconds to load? I have seen many examples using a TaskFactory but I haven\'t been able to apply it to this code. private Uri GetFinalUrl(PortalMerchant portalMerchant) { SetBrowserFeatureControl(); Uri finalUri = null; if (string.IsNullOrEmpty

How can I clear console

二次信任 提交于 2019-11-26 01:16:00
问题 As in the title. How can I clear console in C++? 回答1: For pure C++ You can't. C++ doesn't even have the concept of a console. The program could be printing to a printer, outputting straight to a file, or being redirected to the input of another program for all it cares. Even if you could clear the console in C++, it would make those cases significantly messier. See this entry in the comp.lang.c++ FAQ: http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.20 OS-Specific If it still

How to stop C# console applications from closing automatically? [duplicate]

柔情痞子 提交于 2019-11-26 01:13:27
问题 This question already has an answer here: Why is the console window closing immediately once displayed my output? 21 answers My console applications on Visual Studio are closing automatically, so I\'d like to use something like C\'s system(\"PAUSE\") to \"pause\" the applications at the end of its execution, how can I achieve that? 回答1: Console.ReadLine(); or Console.ReadKey(); ReadLine() waits for ↩ , ReadKey() waits for any key (except for modifier keys). Edit: stole the key symbol from

Masking password input from the console : Java

99封情书 提交于 2019-11-26 01:09:57
问题 How to mask a password from console input? I\'m using Java 6. I\'ve tried using console.readPassword() , but it wouldn\'t work. A full example might help me actually. Here\'s my code: import java.io.BufferedReader; import java.io.Console; import java.io.IOException; import java.io.InputStreamReader; public class Test { public static void main(String[] args) { Console console = System.console(); console.printf(\"Please enter your username: \"); String username = console.readLine(); console

Hide console window from Process.Start C#

喜你入骨 提交于 2019-11-26 01:08:17
问题 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

How to make win32 console recognize ANSI/VT100 escape sequences?

瘦欲@ 提交于 2019-11-26 00:14:38
问题 I\'m building a lightweight version of the ncurses library. So far, it works pretty well with VT100-compatible terminals, but win32 console fails to recognise the \\033 code as the beginning of an escape sequence: # include <stdio.h> # include \"term.h\" int main(void) { puts(BOLD COLOR(FG, RED) \"Bold text\" NOT_BOLD \" is cool!\" CLEAR); return 0; } What needs to be done on the C code level, in order that the ANSI.SYS driver is loaded and the ANSI/VT100 escape sequences recognized? 回答1:

How do I show a console output/window in a forms application?

不羁岁月 提交于 2019-11-25 23:53:38
问题 To get stuck in straight away, a very basic example: using System; using System.Windows.Forms; class test { static void Main() { Console.WriteLine(\"test\"); MessageBox.Show(\"test\"); } } If I compile this with default options (using csc at command line), as expected, it will compile to a console application. Also, because I imported System.Windows.Forms , it will also show a message box. Now, if I use the option /target:winexe , which I think is the same as choosing Windows Application from

.NET Global exception handler in console application

偶尔善良 提交于 2019-11-25 23:34:12
问题 Question: I want to define a global exception handler for unhandled exceptions in my console application. In asp.net, one can define one in global.asax, and in windows applications /services, one can define as below AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyExceptionHandler); But how can I define a global exception handler for a console application ? currentDomain seems not to work (.NET 2.0) ? Edit: Argh,

Show/Hide the console window of a C# console application

做~自己de王妃 提交于 2019-11-25 23:34:06
问题 I googled around for information on how to hide one’s own console window. Amazingly, the only solutions I could find were hacky solutions that involved FindWindow() to find the console window by its title . I dug a bit deeper into the Windows API and found that there is a much better and easier way, so I wanted to post it here for others to find. How do you hide (and show) the console window associated with my own C# console application? 回答1: Here’s how: using System.Runtime.InteropServices;

Listen for key press in .NET console app

为君一笑 提交于 2019-11-25 23:07:07
问题 How can I continue to run my console application until a key press (like Esc is pressed?) I\'m assuming its wrapped around a while loop. I don\'t like ReadKey as it blocks operation and asks for a key, rather than just continue and listen for the key press. How can this be done? 回答1: Use Console.KeyAvailable so that you only call ReadKey when you know it won't block: Console.WriteLine("Press ESC to stop"); do { while (! Console.KeyAvailable) { // Do something } } while (Console.ReadKey(true)