Is there any possible way to automatically append all strings/etc to a textbox(or other form) of my choice? Right now in-order to do that in any class outside of the Main class, I have to route it into it and then use the Main class to post it.
Clarification(CHANGED):
I am no longer looking to just handle exceptions. I really just want to pass a string/text from anywhere in my program without having to pass it to the MainWindow.
namespace MyProgram
{
public partial class MainWindow : Window
{
Main goes here...
}
}
namespace People
{
public class Worker
{
public void printToLog()
{
textBoxErrorlog.AppendText("Message....");
}
}
}
The code above won’t work. I would have to return the string to the MainWindow class and append it from there (bc textBoxErrorlog doesn’t exist in Worker). I would like to skip that step and just post it from the Worker class.
Your question is pretty vague. But I have a feeling you’ll find these events interesting/useful:
EDIT after your added code:
Generally speaking it’s bad to catch
Exception. In your case I would recommend hooking intoAppDomain.CurrentDomain.UnhandledExceptionand in that handler append to the MainWindow’s exception log textbox.And in MainWindow: