SQLite Forum

Stopping a long running operation

Stopping a long running operation

(1) By SM (surabhi.nitsurat) on 2020-04-17 08:53:04 [link] [source]

I m using System.Data.Sqlite in my c# application. I need to run Sqlite cmds in an async manner so that my application is not blocked in case of any rogue query/operation. Since sqlite does not provide any anyc wrappers, I am calling my queries within a Task.Run method.

After waiting for a specified timeout, I want to end the query. I tried calling Connection cancel or connection close from the calling thread to raise an exception in the task and exit the task.

With long queries/updates, closing the connection seems to be working fine, raising an exception on the task and releasing the file handle. Calling Cancel which internally calls interrupt, however, works for long running queries but not for long running updates.

Is it fine to call System.Data.Sqlite connection close from a thread while another thread in performing an operation on it to stop that operation.

(2) By Simon Slavin (slavin) on 2020-04-18 15:54:39 in reply to 1 [source]

You should not close the connection from one thread while another thread is using it. I don't know what will happen under all circumstances but 'undocumented' and 'unpredictable' come to mind.

You didn't mention this function, which seems to be ideal:


It definitely should terminate long-running single statements (e.g. UPDATE working on millions of rows), because it works at a lower level than a single statement. If it doesn't do what you want, please ask again.