Reputation: 8025
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
Reputation: 27
static void Main(string[] args)
{
// do something here...
string answer = Console.ReadLine();
while (answer != "Exit")
{
answer = Console.ReadLine();
}
}
Upvotes: 0
Reputation: 222582
Check this forum
Prevent console app from exiting when it reaches the end of the main
Upvotes: 3
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