NoName
NoName

Reputation: 8025

C# Prevent Console application build as Windows application from exit?

I have a Console application, build as Windows application, to run as background process (I call it App 1).
When I run other app, I send message to App 1, then it process message.
I want prevent App 1 from exit ultil I press a hotkey.

Can you help me how to prevent App 1 from automatic exit? Thank you very much!

Upvotes: 5

Views: 222

Answers (3)

user2289149
user2289149

Reputation: 27

    static void Main(string[] args)
    {
        // do something here...

        string answer = Console.ReadLine();
        while (answer != "Exit")
        {
            answer = Console.ReadLine();
        }
    }

Upvotes: 0

ericosg
ericosg

Reputation: 4965

What you are looking for is how to register a hot key.

Try this:

[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]

public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, int vk);

Source: http://msdn.microsoft.com/en-us/library/ms646309(v=vs.85).aspx

Upvotes: 3

Related Questions