Kill/Cancel/Close ReadKey Task C#

256 Views Asked by At

please is there a way, how to close ReadKey task? I'm using this code in my console application:

            Task _task = Task.Factory.StartNew(() => Console.ReadKey());
            bool result = Task.WaitAny(new Task[] { _task }, TimeSpan.FromSeconds(5)) == 0
                ? true : false;

            if (result)
            {
                ....    
            }
            else
            {
                .....
                //Close ReadKey??
            }

And after using this code I need to use readkey again, but there is still runing the previous one. Any idea how to close first one, when "result" is false.

0

There are 0 best solutions below