You can change your approach slightly - use Console.ReadKey()
to stop your app, but do your work in a background thread:
static void Main(string[] args)
{
var myWorker = new MyWorker();
myWorker.DoStuff();
Console.WriteLine("Press any key to stop...");
Console.ReadKey();
}
In the myWorker.DoStuff()
function you would then invoke another function on a background thread (using Action<>()
or Func<>()
is an easy way to do it), then immediately return.