I'm building a VSTO add-in: I need to run a background thread, but this thread needs to access COM components (I've implemented IMessageFilter to make this messaging as safe as possible). All threads which access OLE or COM have to be STA I believe; thus, BackgroundWorker is off the table.
I am happy to use the normal thread and set the ApartmentState to STA, but I also need to know when this thread as finished so I can update some UI stuff. I do not want to Join() because it will lock the UI (which is the whole reason I'm using threads!).
Is the best practice to trigger some kind of event at the end of my threaded method, and have the event do the onfinished stuff I need?
OR
Is it better to poll
while(!_threadFinishedStarting)
{
Application.DoEvents();
Thread.Sleep(100);
}
As mentioned here: C#.net - How to alert program that the thread is finished (event driven)?
Thanks so much