I am using System.Data.SQLite to store my program’s data and settings (in a WPF Ribbon application).
When you open the program it prompts you to choose a SQLite databse to open, then it reads several settings (Project Name, Last time opened, etc) from the settings table in the SQLite database.
When the application is closed, in the RibbonWindow.Closing event, it calls SQLiteConnection.Close().
Users can also close a database and open a new one.
For some reason, these settings can sometimes take several seconds to show up in the project information view. If a user clicks the application close button during this process or closes the project file to allow them to open a different one, an InvalidOperationException is thrown with the message Database is not open.
What is the best way to just interrupt every operation when the program is closed.
To turn on connection pooling in SqlLite put
pooling = true;in the connection string. It’s an ADO.Net facility, nothing to do with the backend as such.If you use that, instead of passing a connection to the thread, pass the connection parameters. Then each thread will manage it’s own connection.
If you don’t want to do that. Then you have options.
Wait until the thread(s) have finished in a loop, bit crap that unless they are very short.
Busy try again later. Ho hum, user will probably give your app a three fingered salute and kill it anyway.
Kill the thread(s), ugh!
Get thread to create it’s own non pooled connection, and then Dispose of it. NB You can overload a DBMS, if you hammer away creating connections.
Add a boolean property, set it when you close the connection. Don’t close the connection unless it’s not set.
So try connection pooling, it is then.