dotnet / dotnet/SqlClient

SqlDependency async support

Open
#2,412 1 comment 1 reaction 0 assignees View on GitHub
Public API :new: Up-for-Grabs :raised_hands:
Dominant language
C#
Stars
989
Forks
340
Avg merge
4d 18h
Merged PRs (30d)
69

Description

### Is your feature request related to a problem? Please describe.
`SqlDependency` was designed before async was a thing, and it therefore quite hard to work with in a loop.

### Describe the solution you'd like
```csharp
while(!stoppingToken.IsCancellationRequested) {
var command = ...;
var dependency = new AsyncSqlDependency(command, ...);
var whatever = await ProcessResult(command, stoppingToken);
bool falseIfTimeout = await dependency.AwaitDependencyChange(TimeSpan.FromMinutes(1), stoppingToken);
}
```

### Describe alternatives you've considered
It is possible to make an implementation with `TaskCompletionSource`, but would be so much nicer if it was part of the API.

### Additional context
One of the hard things to understand when working with `SqlDependency` is WHEN the dependency is calculated from. The existing implementation is able to call the callback before the `ProcessResult` finished, so in worst case you can have an unlimited of queries ongoing, while it keeps giving you notifications about changes. This is especially a problem, if the `ProcessResult` update the underlying data, and thus triggers it over and over.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.