So i was searching a way to set a hotkey to be able to exit a console application. On my way i found this thread: Global hotkey in console application which helped me a lot. So basically i am setting a hotkey to exit my application. My code looks like this:
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
namespace ConsoleHotKey
{
class Program
{
static void Main(string[] args)
{
HotKeyManager.RegisterHotKey(Keys.A, KeyModifiers.Alt);
HotKeyManager.HotKeyPressed += new EventHandler<HotKeyEventArgs>(HotKeyManager_HotKeyPressed);
Console.ReadLine();
}
static void HotKeyManager_HotKeyPressed(object sender, HotKeyEventArgs e)
{
Environment.Exit(1);
}
}
}
and my question is: Is it a good way to exit a console application like this? I found some poeple saying that it is not such a good way but i couldn't understand why. Can someone give me some clarifications please?