2017-08-03 93 views
0

SqlDependency從應用程序啓動開始並在應用程序停止時停止。有可能會出現SqlDependency.Stop()失敗的情況(例如,連接到數據庫的問題)。據我所知,SqlDependency基礎設施將被超時刪除。確保SqlDependency已停止

但我不明白SqlDependency.Stop()還有什麼功能?

在SqlDependency.Start()之前調用SqlDependency.Stop()是否有意義?

回答

1

在SqlDependency.Start()之前調用SqlDependency.Stop()是否有意義?

如果沒有調用Start(),則調用Stop()是不可操作的。我們可以在SqlDependency.cs參考源

internal static bool Stop(string connectionString, string queue, bool useDefaults, bool startFailed) { 
      ... 
      bool result = false; 

      lock (_startStopLock) { 
       if (null != _processDispatcher) { // If _processDispatcher null, no Start has been called. 
        .... 
       } 
      } 
      return result; 

檢查,以便它不傷害,但它不應該是必要的。