Skip to main content

Posts

Showing posts from April, 2013

Capturing Console Output using c#.net in Windows Form Application

There is a case when we need to use same library code in both console application and windows form application. This is fine if there are no messages displayed in the output window (usually the progress / log messages). one way is to create a log file in a predefined folder (TEMP) and open it after process is complete. Here is one method that can be used to capture the console output and redirected to a text box in the windows form application. Steps Create a new class as given in the snippet Take the temp reference of default output stream of 'Console' class and set new stream output that captures and shows the output in the text box Once new stream is set, all the console output is displayed in the referenced text box After work is done, restore the output stream to default // Create a class for capture using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Form...