I need help with [url=http://pastebin.com/7f11dg8q]this[/URL] code. The issue is that the application won't close when I press ^C. The loop stops and a new tab comes up in Visual Studio like [url=http://data.fuskbugg.se/skogsturken/-bug.png]this[/url]. And yes, this is C#.
[cpp]using System;
using System.Text;
using System.Threading;
class Program
{
static bool quit = false;
static void Main(string[] args)
{
Console.CancelKeyPress += new ConsoleCancelEventHandler(Console_CancelKeyPress);
Console.CursorVisible = false;
MainLoop();
}
static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e)
{
Console.WriteLine("{0} hit, qutting...", e.SpecialKey);
quit = true;
}
static void MainLoop()
{
const int INTERVAL = 500;
Console.WriteLine("Welcome to minidunge0n! You can press CTRL+C to quit the game at any time.");
while (quit != true)
{
Console.WriteLine("test");
Thread.Sleep(INTERVAL);
}
}
}[/cpp]
Check out Console.ReadKey() and it's Key and ModifierKeys properties.
You should use Environment.Exit(0); in your Console_CancelKeyPress-method.
You should also use [code] blocks on FP.
5 days ago.
Take a guess why there's cpp-tags :P
I want them back >:O
Sorry, you need to Log In to post a reply to this thread.