问题
I am experimenting with SqlDependency at the moment. I have a watching console application that really does not do anything than creating the SqlDependency object on a defined SqlCommand and then call dependency.Start(); The statement to be watched contains 2 inner joins.
To test this now, I wrote another console app that updates a record that should change the result of the defined query. The data in these tables is about 1 million rows / table. Now when calling the method that executes the update statement, the background checking process of SQL Server takes really long (5secs) which blocks the calling method. update without watching is about 20ms.
is there maybe an async approach that does not block my calling method? or what do you suggest to do? i also thought about setting the notification object on my SqlCommand. This creates an entry in sys.dm_qn_subscriptions. But what is the best way to react on entries in this view? use a seperate service that uses polling to this table? i really liked the concept of hanging onto an event when something changes.
来源:https://stackoverflow.com/questions/22932734/use-of-sqldependency-blocks-executing-method