@@ -252,11 +252,10 @@ internal bool AppDomainUnload(string appDomainKey)
252252 // For each decrement, subtract from count, and delete if we reach 0.
253253 lock ( _appDomainKeyHash )
254254 {
255- if ( _appDomainKeyHash . ContainsKey ( appDomainKey ) )
255+ if ( _appDomainKeyHash . TryGetValue ( appDomainKey , out int value ) )
256256 {
257257 // Do nothing if AppDomain did not call Start!
258258 SqlClientEventSource . Log . TryNotificationTraceEvent ( "<sc.SqlConnectionContainer.AppDomainUnload|DEP> _appDomainKeyHash contained AppDomainKey: '{0}'." , appDomainKey ) ;
259- int value = _appDomainKeyHash [ appDomainKey ] ;
260259 SqlClientEventSource . Log . TryNotificationTraceEvent ( "SqlConnectionContainer.AppDomainUnload|DEP> _appDomainKeyHash for AppDomainKey: '{0}' count: '{1}'." , appDomainKey , value ) ;
261260 Debug . Assert ( value > 0 , "Why is value 0 or less?" ) ;
262261
@@ -272,9 +271,9 @@ internal bool AppDomainUnload(string appDomainKey)
272271 Debug . Assert ( 0 == value , "We did not reach 0 at end of loop in AppDomainUnload!" ) ;
273272 Debug . Assert ( ! _appDomainKeyHash . ContainsKey ( appDomainKey ) , "Key not removed after AppDomainUnload!" ) ;
274273
275- if ( _appDomainKeyHash . ContainsKey ( appDomainKey ) )
274+ if ( _appDomainKeyHash . TryGetValue ( appDomainKey , out int remainingCount ) )
276275 {
277- SqlClientEventSource . Log . TryNotificationTraceEvent ( "SqlConnectionContainer.AppDomainUnload|DEP|ERR> ERROR - after the Stop() loop, _appDomainKeyHash for AppDomainKey: '{0}' entry not removed from hash. Count: {1}'" , appDomainKey , _appDomainKeyHash [ appDomainKey ] ) ;
276+ SqlClientEventSource . Log . TryNotificationTraceEvent ( "SqlConnectionContainer.AppDomainUnload|DEP|ERR> ERROR - after the Stop() loop, _appDomainKeyHash for AppDomainKey: '{0}' entry not removed from hash. Count: {1}'" , appDomainKey , remainingCount ) ;
278277 }
279278 }
280279 else
@@ -510,10 +509,11 @@ internal void IncrementStartCount(string appDomainKey, out bool appDomainStart)
510509 // For each increment, add to count, and create entry if not present.
511510 lock ( _appDomainKeyHash )
512511 {
513- if ( _appDomainKeyHash . ContainsKey ( appDomainKey ) )
512+ if ( _appDomainKeyHash . TryGetValue ( appDomainKey , out int count ) )
514513 {
515- _appDomainKeyHash [ appDomainKey ] = _appDomainKeyHash [ appDomainKey ] + 1 ;
516- SqlClientEventSource . Log . TryNotificationTraceEvent ( "SqlConnectionContainer.IncrementStartCount|DEP> _appDomainKeyHash contained AppDomainKey: '{0}', incremented count: '{1}'." , appDomainKey , _appDomainKeyHash [ appDomainKey ] ) ;
514+ count ++ ;
515+ _appDomainKeyHash [ appDomainKey ] = count ;
516+ SqlClientEventSource . Log . TryNotificationTraceEvent ( "SqlConnectionContainer.IncrementStartCount|DEP> _appDomainKeyHash contained AppDomainKey: '{0}', incremented count: '{1}'." , appDomainKey , count ) ;
517517 }
518518 else
519519 {
@@ -1618,7 +1618,7 @@ private bool Start(
16181618 {
16191619 if ( ! _sqlDependencyPerAppDomainDispatchers . ContainsKey ( appDomainKey ) )
16201620 {
1621- _sqlDependencyPerAppDomainDispatchers [ appDomainKey ] = dispatcher ;
1621+ _sqlDependencyPerAppDomainDispatchers . Add ( appDomainKey , dispatcher ) ;
16221622 }
16231623 }
16241624
@@ -1637,7 +1637,7 @@ private bool Start(
16371637 SqlConnectionContainer container = null ;
16381638 lock ( _connectionContainers )
16391639 {
1640- if ( ! _connectionContainers . ContainsKey ( hashHelper ) )
1640+ if ( ! _connectionContainers . TryGetValue ( hashHelper , out container ) )
16411641 {
16421642 SqlClientEventSource . Log . TryNotificationTraceEvent ( "<sc.SqlDependencyProcessDispatcher.Start|DEP> {0}, hashtable miss, creating new container." , ObjectID ) ;
16431643 container = new SqlConnectionContainer ( hashHelper , appDomainKey , useDefaults ) ;
@@ -1647,7 +1647,6 @@ private bool Start(
16471647 }
16481648 else
16491649 {
1650- container = _connectionContainers [ hashHelper ] ;
16511650 SqlClientEventSource . Log . TryNotificationTraceEvent ( "<sc.SqlDependencyProcessDispatcher.Start|DEP> {0}, hashtable hit, container: {1}" , ObjectID , container . ObjectID ) ;
16521651 if ( container . InErrorState )
16531652 {
@@ -1713,9 +1712,8 @@ internal bool Stop(
17131712
17141713 lock ( _connectionContainers )
17151714 {
1716- if ( _connectionContainers . ContainsKey ( hashHelper ) )
1715+ if ( _connectionContainers . TryGetValue ( hashHelper , out SqlConnectionContainer container ) )
17171716 {
1718- SqlConnectionContainer container = _connectionContainers [ hashHelper ] ;
17191717 SqlClientEventSource . Log . TryNotificationTraceEvent ( "<sc.SqlDependencyProcessDispatcher.Stop|DEP> {0}, hashtable hit, container: {1}" , ObjectID , container . ObjectID ) ;
17201718 server = container . Server ; // Return server, database, and queue info for use by calling SqlDependency.
17211719 database = container . Database ;
0 commit comments