Skip to content

Instantly share code, notes, and snippets.

@timgaunt
Created September 4, 2012 11:00
Show Gist options
  • Save timgaunt/3620149 to your computer and use it in GitHub Desktop.
Save timgaunt/3620149 to your computer and use it in GitHub Desktop.
Non blocking Console.WriteLine
public static class NonBlockingConsole
{
private BlockingCollection<string> m_Queue = new BlockingCollection<string>();
static NonBlockingConsole()
{
var thread = new Thread(
() =>
{
while (true) Console.WriteLine(m_Queue.Take());
});
thread.IsBackground = true;
thread.Start();
}
public static void WriteLine(string value)
{
m_Queue.Add(value);
}
)
@timgaunt
Copy link
Author

timgaunt commented Sep 4, 2012

@usernamedd
Copy link

the console sometimes does not show the content until I resize the console window . But I konw it not blocking。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment