// This method is called when a connection goes down or other unknown error occurs in the ProcessDispatcher. internal void InvalidateServer(string server, SqlNotification sqlNotification) { IntPtr hscp; Bid.NotificationsScopeEnter(out hscp, "<sc.SqlDependencyPerAppDomainDispatcher.Invalidate|DEP> %d#, server: '%ls'", ObjectID, server); try { List <SqlDependency> dependencies = new List <SqlDependency>(); lock (this) { // Copy inside of lock, but invalidate outside of lock. foreach (KeyValuePair <string, SqlDependency> entry in _dependencyIdToDependencyHash) { SqlDependency dependency = entry.Value; if (dependency.ContainsServer(server)) { dependencies.Add(dependency); } } foreach (SqlDependency dependency in dependencies) // Iterate over resulting list removing from our hashes. // Ensure we remove from process static app domain hash for dependency initiated invalidates. { LookupDependencyEntryWithRemove(dependency.Id); // Completely remove Dependency from commandToDependenciesHash. RemoveDependencyFromCommandToDependenciesHash(dependency); } } foreach (SqlDependency dependency in dependencies) // Iterate and invalidate. { try { dependency.Invalidate(sqlNotification.Type, sqlNotification.Info, sqlNotification.Source); } catch (Exception e) { // Since we are looping over dependencies, do not allow one Invalidate // that results in a throw prevent us from invalidating all dependencies // related to this server. if (!ADP.IsCatchableExceptionType(e)) { throw; } ADP.TraceExceptionWithoutRethrow(e); } } } finally { Bid.ScopeLeave(ref hscp); } }
internal void InvalidateServer(string server, SqlNotification sqlNotification) { IntPtr ptr; Bid.NotificationsScopeEnter(out ptr, "<sc.SqlDependencyPerAppDomainDispatcher.Invalidate|DEP> %d#, server: '%ls'", this.ObjectID, server); try { List <SqlDependency> list = new List <SqlDependency>(); lock (this) { foreach (KeyValuePair <string, SqlDependency> pair in this._dependencyIdToDependencyHash) { SqlDependency item = pair.Value; if (item.ContainsServer(server)) { list.Add(item); } } foreach (SqlDependency dependency in list) { this.LookupDependencyEntryWithRemove(dependency.Id); this.RemoveDependencyFromCommandToDependenciesHash(dependency); } } foreach (SqlDependency dependency3 in list) { try { dependency3.Invalidate(sqlNotification.Type, sqlNotification.Info, sqlNotification.Source); } catch (Exception exception) { if (!ADP.IsCatchableExceptionType(exception)) { throw; } ADP.TraceExceptionWithoutRethrow(exception); } } } finally { Bid.ScopeLeave(ref ptr); } }
// This method is called when a connection goes down or other unknown error occurs in the ProcessDispatcher. internal void InvalidateServer(string server, SqlNotification sqlNotification) { List <SqlDependency> dependencies = new List <SqlDependency>(); lock (_instanceLock) { // Copy inside of lock, but invalidate outside of lock. foreach (KeyValuePair <string, SqlDependency> entry in _dependencyIdToDependencyHash) { SqlDependency dependency = entry.Value; if (dependency.ContainsServer(server)) { dependencies.Add(dependency); } } foreach (SqlDependency dependency in dependencies) { // Iterate over resulting list removing from our hashes. // Ensure we remove from process static app domain hash for dependency initiated invalidates. LookupDependencyEntryWithRemove(dependency.Id); // Completely remove Dependency from commandToDependenciesHash. RemoveDependencyFromCommandToDependenciesHash(dependency); } } foreach (SqlDependency dependency in dependencies) { // Iterate and invalidate. try { dependency.Invalidate(sqlNotification.Type, sqlNotification.Info, sqlNotification.Source); } catch (Exception e) { // Since we are looping over dependencies, do not allow one Invalidate // that results in a throw prevent us from invalidating all dependencies // related to this server. if (!ADP.IsCatchableExceptionType(e)) { throw; } ADP.TraceExceptionWithoutRethrow(e); } } }