Start Method (int, int)

Starts the listener for receiving dependency change notifications from the instance of SQL Server specified by the connection string.

Syntax

public void Start(int timeOut = 120, int watchDogTimeOut = 180)

Parameters

timeOut
Type: System.Int32 (Optional)
Specify the amount of time in seconds the SQL listener command must wait for a notification before start a new request.

watchDogTimeOut
Type: System.Int32 (Optional)
Specify the amount of time in seconds for the watch dog.

Remark

It is a good practice is to wrap SqlTableDependency within a using statement or, alternatively, call the Stop() method once we do not need any more notifications. So, when the application will not disconnect abruptly, this approach is enough to remove the SqlTableDependency infrastructure (Trigger, Service Broker service, the queue, Contract, Messages type and Stored Procedure).

However, when the application exits abruptly – that is not calling the Stop() method or not implementing the using statement - we need a way for cleaning up the SqlTableDependency infrastructure. The Start() method, has watchDogTimeOut optional parameter used to remove all the database objects. Its default value is 180 seconds: after this amount of time, if there are no listeners waiting for notifications, the SqlTableDependency infrastructure will be removed. This time seems long enough. Or not?

There is one very common scenario that results in much more time: debugging. When you develop applications, you often spend several minutes inside the debugger before you move on. So please be careful when you debug an application that the value assigned to watchDogTimeOut parameter is long enough, otherwise you will incur in a destruction of database objects in the middle of you debug activity.

Last edited Sep 10, 2015 at 10:26 AM by delbianco, version 4