I am attempting to run an async output that will last a large amount of time, and then closing the application during execution which causes the textbox to dispose. I thought this would be handled by simply returning in a try-catch statement, but VS still says there is an "unhandled" exception. Here is the code:
public void AppendOutput(string text)
{
var timeNow = DateTime.Now;
if ((DateTime.Now - previousTime).Milliseconds <= 50) return;
try
{
synchronizationContext.Post(new SendOrPostCallback(o =>
{
Output.AppendText((string)o);
}), text);
}
catch(ObjectDisposedException e)
{
return;
}
previousTime = timeNow;
}
Here is what happens in debug:
I there a reason why this is considered unhandled? I thought that's what try-catch was for. My understanding was that I could simply return because there's no need to handle exceptions for a program that is attempting to write to a textbox that has been disposed; the program should be ending the thread on its own. What is the correct way to deal with this problem?