I have a function that should work like an STA, and I want to propagate its exceptions to call the stream. There he is:
public void ExceptionBePropagatedThroughHere()
{
Thread thread = new Thread(TheSTAThread);
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
}
public void MainFunction()
{
try
{
ExceptionBePropagatedThroughHere();
}
catch(Exception e)
{
}
}
Including the STA attribute in "MainFunction" is not an option here. I noticed that if I used Task, try catch on task join will throw the exception to the calling thread, however I cannot specify the task start as STA.
The question is how to propagate an exception that works as an STA to the "MainFunction" in the ablove example?
Thanks in advance.
Yuan source
share