Skip to content

Instantly share code, notes, and snippets.

@renestein
Last active December 16, 2015 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renestein/5434943 to your computer and use it in GitHub Desktop.
Save renestein/5434943 to your computer and use it in GitHub Desktop.
Avoid lock in console - .Net 4.,5
// https://twitter.com/jechtom/status/326325740503175169
using System;
using System.Threading;
internal class Program
{
private static void Main(string[] args)
{
Console.Error.WriteLine("Dummy error init");
Console.WriteLine("Dummy init");
Thread t = new Thread(SomeWorkingThread);
t.Start();
while (Console.ReadKey().Key != ConsoleKey.Escape)
{
}
}
private static void SomeWorkingThread()
{
int i = 0;
while (true)
{
Thread.Sleep(TimeSpan.FromSeconds(0.5));
Console.WriteLine("Working... {0}", ++i);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment