I've written this code in C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Program re = new Program();
re.actual();
}
public void actual()
{
Thread input = new Thread(input_m);
Thread timing = new Thread(timing_m);
input.Start();
timing.Start();
}
public void input_m()
{
Console.WriteLine("Choose a number from 1-10 (You have 10 seconds): ");
Console.ReadKey();
}
public void timing_m()
{
System.Threading.Thread.Sleep(10000);
input.Abort();
Console.Clear();
Console.WriteLine("Time's up!");
Console.ReadKey();
}
}
}
Now, I get this error:
Error 1 The name 'input' does not exist in the current context
It says that about the "input.Abort();" line.
Can I somehow terminate this thread from another methods (not from where it was created)?
I don't want to make them static by the way, so please don't suggest that.