Alex Rivera | Logout

Does Console.WriteLine block?

Asked 2010-09-08T16:51:44.337
52

Does Console.WriteLine block until the output has been written or does it return immediately?

If it does block is there a method of writing asynchronous output to the Console?

Edit
Report

1 Answer

1

A quick test at my desk would suggest that yes, it blocks.

To asynchronously write to the console you could just send your writes to another thread that could then write them out. You could do that by either having another thread spinning that has a queue of messages to write, or by chaining Task instances so that your writes are ordered.

My previous suggestion of using the thread pool is a bad one as it won't guarantee ordering and therefore, your console output could be mixed up.

answered 2010-09-08T16:59:59.153

Your Answer