Ensure SqlDependency was Stopped

不打扰是莪最后的温柔 提交于 2019-12-25 08:57:41

问题


SqlDependency starts on application start and stops on app stop. There are can be cases when SqlDependency.Stop() failed (for example, problem with connect to DB). As I understand, the SqlDependency infrastructure will be removed anyway by timeout.

But I don't understand what else SqlDependency.Stop() do?

Does it make sense to call SqlDependency.Stop() before SqlDependency.Start()?


回答1:


Does it make sense to call SqlDependency.Stop() before SqlDependency.Start()?

If Start() was not called, calling Stop() is a no-op. We can check in the SqlDependency.cs reference source

   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;

So it doesn't hurt, but it shouldn't be needed.



来源:https://stackoverflow.com/questions/45478012/ensure-sqldependency-was-stopped

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!