internal void CloseRecursive() {
if (!_flags[Closed]) {
bool doClose = false;
HybridDictionary streamInfos = null;
StreamChangeCallback callbackDelegate = null;
lock (this) {
if (!_flags[Closed]) {
_flags[Closed] = true;
doClose = true;
if (!IsLocationConfig && ConfigStreamInfo.HasStreamInfos) {
callbackDelegate = ConfigStreamInfo.CallbackDelegate;
streamInfos = ConfigStreamInfo.StreamInfos;
ConfigStreamInfo.CallbackDelegate = null;
ConfigStreamInfo.ClearStreamInfos();
}
}
}
if (doClose) {
// no hierarchy lock is needed to access _children here,
// as it has already been detached from the hierarchy tree
if (_children != null) {
foreach (BaseConfigurationRecord child in _children.Values) {
child.CloseRecursive();
}
}
if (streamInfos != null) {
foreach (StreamInfo streamInfo in streamInfos.Values) {
if (streamInfo.IsMonitored) {
Host.StopMonitoringStreamForChanges(streamInfo.StreamName, callbackDelegate);
streamInfo.IsMonitored = false;
}
}
}
}
}
}