I am curious. I run this in the background and i know when its done when i see the console disappear. I can check the status by clicking on it and see the output. Then i decided to add a quit button. It no longer disappears when done (it can stay alive for minutes or hours) but once i click on the console it ends. Why?
I wrote this to show an example of how my app runs. If you run it you'll notice the problem. I compiled with msvc 2008 running on windows 7.
I notice now. It quits on an event like focus like mouse move, on of lose focus. etc. A still mouse on focus will not make it quit. Why? Any work around to killing the thread or avoid killing the thread and not eat cpu?
-edit- you can press q to quit
using System;
using System.Threading;
namespace ConsoleExitTest
{
class Program
{
static object dummy = new object();
static bool wantQuit = false;
static void line() { while (wantQuit == false) { if (Console.ReadKey().Key == ConsoleKey.Q) { wantQuit = true; lock (dummy) { Monitor.Pulse(dummy); }; } } }
static void Main(string[] args)
{
//opt stuff here
Thread t = new Thread(line); t.Start();
Console.WriteLine("My code here");
for (int i = 0; i < 3 && wantQuit == false; i++)
{
lock (dummy)
{
Monitor.Wait(dummy, 1000);
}
}
wantQuit = false;
t.Abort();
}
}
}