I am converting a console application into a Windows Forms application and a DLL. A Windows Forms application uses BackgroundWorker to make a DLL perform a complex computing task.
Remaining from the console application, the DLL is still dotted with Console.WriteLine() statements. I would like to direct what was previously printed on the console to a TextBox in Windows Form. Ideally, I would like to connect the stream from the DLL to the text field during the initialization of the form and execute with it. I am worried that this may not be thread safe with BackgroundWorker.
The best approach I found is to change Console.WriteLine() to Trace.WriteLine() in the DLL, and then follow the approach in the trace listener to write to the text field (WPF application) , but I still have problems with BackgroundWorker and I'm not too keen on adding text to an existing line (there is a lot of text, but IMO lines are not designed / optimized to have a lot of text concatenated on them).
What is the best way to print old console output into a text box that will be safe with BackgroundWorker?
source share