In my Windows Forms app I use Console.WriteLine to spew debugging information to Visual Studio's Output window. I prefer this to Debug.WriteLine because it works even for Release builds, and for speed reasons I need to do my debugging in Release mode. But I wonder: if I leave those Console.WriteLines in my app and deploy it, will they affect the speed of the deployed version? I know that Visual Studio somehow "attaches" to the app's console output to show the results of Console.WriteLine. My question is, when nothing is attached in that fashion, is Console.WriteLine a no-op (or at least a very fast operation)?
After reading the forum thread linked by @bwegs, I decided to do a quick test. A million calls to Console.WriteLine with the debugger attached took a long time (actually I stopped the app rather than let it run to completion). Running the same exe from File Explorer (not attached to the debugger), the same million calls returned essentially immediately. So, for my purposes, Console.WriteLine is fast enough without a console attached to leave in my application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With