Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi, I anticipated I was implementing this in Issue #1174 (this code contains also the small fix I proposed in pull request #1175 )
This modification extends SQLiteConnection and SQLiteAsyncConnection with a mechanism that allows to terminate long running queries by the means of setting a cancellation token.
to interrupt "sqlite server side" processing it makes use of the sqlite3_interrupt() api, that I had to map myself, since it wasn't already imported in the source code. to interrupt record fetch loops it checks the cancellation token status for each record fetched.
When an operation is aborted by the cancellation token you always get a OperationCanceledException.
I added also some tests of this feature.
for connection.Table() access methods I added a specific CancelToken(cancTok) call to be added in the "builder pattern" chain, so a cancellable query would look like this:
of course tokSource.Cancel() must be executed by some other task while the query is still executing.
Whenever possible, I added an optional CancellationToken? cancTok=null parameter to existing apis, but for Apis that were expecting a params args[] for the last parameter, this wasn't possible. in such cases I defined an overloaded version that accepts the cancellation token as first parameter.
For example I had to define a sqliteConnection.Query(CancellationToken tok, string sql, params args[]) overload.
background : why I need this?
I have an android application where the end user can type a search criteria and see the results of that search criteria being found immediately every time he changes the search text, even while he is typing (actually the query is re-executed whenever the user stops typing for at least 300 ms). the problem is that, if the table contains a lot of data I really need to be able to cancel the execution of the current query (if it has not finished yet) as soon the user starts typing again.
it might be useful also in other scenarios, but in the one I need it it would really make the application much more responsive.