Ensure SqlDependency was Stopped

2019-08-16 09:36发布

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条回答
劫难
2楼-- · 2019-08-16 10:24

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.

查看更多
登录 后发表回答