c# instantly kill thread with TerminateThread (danger)
[DllImport("kernel32.dll")]
static extern bool TerminateThread(int hThread, uint dwExitCode);
//[STAThread]
static void Main(string[] args)
{
try
{
Thread t = new Thread(() =>
{
//code even interop
});
t.IsBackground = true; //check out this line
t.Start();
Console.Title = ("Hit Enter to stop");
Console.ReadLine();
uint dwExitCode = 0;
TerminateThread(t.ManagedThreadId, dwExitCode); //and this line
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.ReadKey();
}
}