G
GM
Hi,
My application has a need to cache a number of shared reference lists
containing basic business objects. In order to improve performance these
lists are fetched and updated in the background.
When a UI is required to display one of these reference lists it requests it
by name from the cache. If the list already exists in the cache it is
returned to the caller otherwise a brand new empty one is created and
returned. This new empty list then initiates a background thread to fetch
the items from the database. On return the contents of the list are merged
with the empty list in the cache and the appropriate ListChanged events
raised to notify observing controls that the list has changed.
I use Joval Lowy's BackgroundWorker
(http://www.idesign.net/idesign/desktopdefault.aspx?tabindex=5&tabid=8) to
perform the background fetch.
My problem is that the merge/update to the cached list takes place on the
background thread. This results in a ListChanged event being raised on that
thread and the control that the list is bound to being updated on a thread
other than the one that created it. I would like to be able to return to the
main thread when the background thread has finished its work of fetching the
list. This would allow the main thread to perform the update of the cached
list and the raising of the ListChanged event. I have read about the
ISynchronizeInvoke interface and thought that that would be the way to go
but I cannot see how to marshall back to the main thread other than to use
PostMessage.
Am I missing something obvious?
Thanks in advance,
Graham
My application has a need to cache a number of shared reference lists
containing basic business objects. In order to improve performance these
lists are fetched and updated in the background.
When a UI is required to display one of these reference lists it requests it
by name from the cache. If the list already exists in the cache it is
returned to the caller otherwise a brand new empty one is created and
returned. This new empty list then initiates a background thread to fetch
the items from the database. On return the contents of the list are merged
with the empty list in the cache and the appropriate ListChanged events
raised to notify observing controls that the list has changed.
I use Joval Lowy's BackgroundWorker
(http://www.idesign.net/idesign/desktopdefault.aspx?tabindex=5&tabid=8) to
perform the background fetch.
My problem is that the merge/update to the cached list takes place on the
background thread. This results in a ListChanged event being raised on that
thread and the control that the list is bound to being updated on a thread
other than the one that created it. I would like to be able to return to the
main thread when the background thread has finished its work of fetching the
list. This would allow the main thread to perform the update of the cached
list and the raising of the ListChanged event. I have read about the
ISynchronizeInvoke interface and thought that that would be the way to go
but I cannot see how to marshall back to the main thread other than to use
PostMessage.
Am I missing something obvious?
Thanks in advance,
Graham