Existing problem: A function that runs on a thread needs to return
data to the UI thread. When the data is returned, that will trigger
secondary tasks, including access to form controls and lookup of data
within a database.
I'm not sure of the implications of using data returned by the thread
within database access code, but I do know about InvokeRequired() etc
for access to forms controls. I've used that often when individual
controls are the focal point. Not so here.
In this case, I'd like to simplify things by marshaling ALL data
coming back from the thread. Then it could be used by controls or
other functions with no worries. So the thread would return data
through a 'channel object' that takes care of all marshaling in one
place.
As for the mechanics involved:
InvokeRequired() is associated with a specific control, so that is not
relevant.
BackgroundWorker seems like it might be applicable, but I haven't seen
it used in the context, maybe for good reason.
SynchronizationContext seems like a good clue but I have not been able
to find enough info on actual usage to be sure that this is the
simplest approach.
Thanks for any perspective you can provide.