@@ -29,24 +29,24 @@ internal class SqlDependencyProcessDispatcher : MarshalByRefObject
2929 // Class to contain/store all relevant information about a connection that waits on the SSB queue.
3030 private class SqlConnectionContainer
3131 {
32- private SqlConnection _con ;
33- private SqlCommand _com ;
34- private SqlParameter _conversationGuidParam ;
35- private SqlParameter _timeoutParam ;
36- private SqlConnectionContainerHashHelper _hashHelper ;
32+ private readonly SqlConnection _con ;
33+ private readonly SqlCommand _com ;
34+ private readonly SqlParameter _conversationGuidParam ;
35+ private readonly SqlParameter _timeoutParam ;
36+ private readonly SqlConnectionContainerHashHelper _hashHelper ;
3737#if NETFRAMEWORK
38- private WindowsIdentity _windowsIdentity ;
38+ private readonly WindowsIdentity _windowsIdentity ;
3939#endif
40- private string _queue ;
41- private string _receiveQuery ;
40+ private readonly string _queue ;
41+ private readonly string _receiveQuery ;
4242 private string _beginConversationQuery ;
4343 private string _endConversationQuery ;
4444 private string _concatQuery ;
4545 private readonly int _defaultWaitforTimeout = 60000 ; // Waitfor(Receive) timeout (milleseconds)
46- private string _escapedQueueName ;
47- private string _sprocName ;
46+ private readonly string _escapedQueueName ;
47+ private readonly string _sprocName ;
4848 private string _dialogHandle ;
49- private string _cachedServer ;
49+ private readonly string _cachedServer ;
5050 private string _cachedDatabase ;
5151 private volatile bool _errorState = false ;
5252 private volatile bool _stop = false ; // Can probably simplify this slightly - one bool instead of two.
@@ -55,10 +55,10 @@ private class SqlConnectionContainer
5555 private int _startCount = 0 ; // Each container class is called once per Start() - we refCount
5656 // to track when we can dispose.
5757 private Timer _retryTimer = null ;
58- private Dictionary < string , int > _appDomainKeyHash = null ; // AppDomainKey->Open RefCount
58+ private readonly Dictionary < string , int > _appDomainKeyHash = null ; // AppDomainKey->Open RefCount
5959
60- private static int _objectTypeCount ; // EventSource counter
61- internal int ObjectID { get ; } = Interlocked . Increment ( ref _objectTypeCount ) ;
60+ private static int s_objectTypeCount ; // EventSource counter
61+ internal int ObjectID { get ; } = Interlocked . Increment ( ref s_objectTypeCount ) ;
6262
6363 // Constructor
6464
@@ -285,7 +285,7 @@ private void AsynchronouslyQueryServiceBrokerQueue()
285285 long scopeID = SqlClientEventSource . Log . TryNotificationScopeEnterEvent ( "<sc.SqlConnectionContainer.AsynchronouslyQueryServiceBrokerQueue|DEP> {0}" , ObjectID ) ;
286286 try
287287 {
288- AsyncCallback callback = new AsyncCallback ( AsyncResultCallback ) ;
288+ AsyncCallback callback = new ( AsyncResultCallback ) ;
289289 _com . BeginExecuteReader ( callback , null , CommandBehavior . Default ) ; // NO LOCK NEEDED
290290 }
291291 finally
@@ -351,7 +351,7 @@ private void CreateQueueAndService(bool restart)
351351 long scopeID = SqlClientEventSource . Log . TryNotificationScopeEnterEvent ( "<sc.SqlConnectionContainer.CreateQueueAndService|DEP> {0}" , ObjectID ) ;
352352 try
353353 {
354- SqlCommand com = new SqlCommand ( )
354+ SqlCommand com = new ( )
355355 {
356356 Connection = _con
357357 } ;
@@ -439,7 +439,7 @@ private void CreateQueueAndService(bool restart)
439439 + " END;"
440440 + " BEGIN DIALOG @dialog_handle FROM SERVICE " + _escapedQueueName + " TO SERVICE " + nameLiteral ;
441441
442- SqlParameter param = new SqlParameter ( )
442+ SqlParameter param = new ( )
443443 {
444444 ParameterName = "@dialog_handle" ,
445445 DbType = DbType . Guid ,
@@ -1218,7 +1218,7 @@ internal static SqlNotification ProcessMessage(SqlXml xmlMessage)
12181218 }
12191219
12201220 // Create a new XmlTextReader on the Message node value. Prohibit DTD processing when dealing with untrusted sources.
1221- using ( XmlTextReader xmlMessageReader = new XmlTextReader ( xmlReader . Value , XmlNodeType . Element , null ) { DtdProcessing = DtdProcessing . Prohibit } )
1221+ using ( XmlTextReader xmlMessageReader = new ( xmlReader . Value , XmlNodeType . Element , null ) { DtdProcessing = DtdProcessing . Prohibit } )
12221222 {
12231223 // Proceed to the Text Node.
12241224 if ( ! xmlMessageReader . Read ( ) )
@@ -1260,10 +1260,10 @@ private class SqlConnectionContainerHashHelper
12601260
12611261 // As a result, we will not use _connectionStringBuilder as part of Equals or GetHashCode.
12621262
1263- private DbConnectionPoolIdentity _identity ;
1264- private string _connectionString ;
1265- private string _queue ;
1266- private SqlConnectionStringBuilder _connectionStringBuilder ; // Not to be used for comparison!
1263+ private readonly DbConnectionPoolIdentity _identity ;
1264+ private readonly string _connectionString ;
1265+ private readonly string _queue ;
1266+ private readonly SqlConnectionStringBuilder _connectionStringBuilder ; // Not to be used for comparison!
12671267
12681268 internal SqlConnectionContainerHashHelper ( DbConnectionPoolIdentity identity , string connectionString ,
12691269 string queue , SqlConnectionStringBuilder connectionStringBuilder )
@@ -1285,7 +1285,7 @@ public override bool Equals(object value)
12851285 {
12861286 SqlConnectionContainerHashHelper temp = ( SqlConnectionContainerHashHelper ) value ;
12871287
1288- bool result = false ;
1288+ bool result ;
12891289
12901290 // Ignore SqlConnectionStringBuilder, since it is present largely for debug purposes.
12911291
@@ -1358,14 +1358,14 @@ public override int GetHashCode()
13581358
13591359 // SqlDependencyProcessDispatcher static members
13601360
1361- private static SqlDependencyProcessDispatcher s_staticInstance = new SqlDependencyProcessDispatcher ( null ) ;
1361+ private static readonly SqlDependencyProcessDispatcher s_staticInstance = new ( null ) ;
13621362
13631363 // Dictionaries used as maps.
1364- private Dictionary < SqlConnectionContainerHashHelper , SqlConnectionContainer > _connectionContainers ; // NT_ID+ConStr+Service->Container
1365- private Dictionary < string , SqlDependencyPerAppDomainDispatcher > _sqlDependencyPerAppDomainDispatchers ; // AppDomainKey->Callback
1364+ private readonly Dictionary < SqlConnectionContainerHashHelper , SqlConnectionContainer > _connectionContainers ; // NT_ID+ConStr+Service->Container
1365+ private readonly Dictionary < string , SqlDependencyPerAppDomainDispatcher > _sqlDependencyPerAppDomainDispatchers ; // AppDomainKey->Callback
13661366
1367- private static int _objectTypeCount ; //EventSource counter
1368- internal int ObjectID { get ; } = Interlocked . Increment ( ref _objectTypeCount ) ;
1367+ private static int s_objectTypeCount ; //EventSource counter
1368+ internal int ObjectID { get ; } = Interlocked . Increment ( ref s_objectTypeCount ) ;
13691369 // Constructors
13701370
13711371 // Private constructor - only called by public constructor for static initialization.
@@ -1521,7 +1521,7 @@ private void AppDomainUnloading(object state)
15211521 Debug . Assert ( this == s_staticInstance , "Instance method called on non _staticInstance instance!" ) ;
15221522 lock ( _connectionContainers )
15231523 {
1524- List < SqlConnectionContainerHashHelper > containersToRemove = new List < SqlConnectionContainerHashHelper > ( ) ;
1524+ List < SqlConnectionContainerHashHelper > containersToRemove = new ( ) ;
15251525
15261526 foreach ( KeyValuePair < SqlConnectionContainerHashHelper , SqlConnectionContainer > entry in _connectionContainers )
15271527 {
@@ -1589,15 +1589,15 @@ internal bool Start(
15891589 Debug . Assert ( this == s_staticInstance , "Instance method called on non _staticInstance instance!" ) ;
15901590 return Start (
15911591 connectionString ,
1592- out string dummyValue1 ,
1593- out DbConnectionPoolIdentity dummyValue3 ,
1594- out dummyValue1 ,
1595- out dummyValue1 ,
1592+ out _ ,
1593+ out _ ,
1594+ out _ ,
1595+ out _ ,
15961596 ref queue ,
15971597 appDomainKey ,
15981598 dispatcher ,
1599- out bool dummyValue2 ,
1600- out dummyValue2 ,
1599+ out _ ,
1600+ out _ ,
16011601 false ) ;
16021602 }
16031603
0 commit comments