I recently identified a bug with a fairly mature application I've developed which is hosted through ArcMap. The bug happens when I've loaded a 'project' into ArcMap, which includes assorted feature layers and standalone geodatabase tables. When a user chooses to close out of the active project and load a new project, I've noticed that while the previous project layers and tables appear removed from the 'Contents' view of the Table-of-Contents (TOC), the previous project geodatabase 'data source' is retained in the 'Source' view of the TOC.
The reason this is happening seems to me to be related to the fact the original call to create a new document hasn't quite finished by the time I begin loading my new data. I suppose I could track that down eventually.
But my question surrounds the TOC itself. A possible workaround might be to test the TOC during this 'load' sequence and ensure it's been properly cleared. Unfortunately, for the life of me I can't seem to identify the proper interface to acquire the collection of data sources attached to a TOC and remove the one(s) I don't want.
The closest I've come is this link which describes how to acquire the Source Contents view object/interface. Unfortunately, that particular interface (IContentsView) isn't very helpful in exposing the current collection of data sources...
I'd appreciate any thoughts, speculation and/or advice anyone might have.