Sleeping the main thread

Until case 42544 is fixed, I’m looking at coding up a workaround. This case relates to the fact that, if two threads try to write to an SQLite db at the same time, one may get “database is locked”. Ordinarily, setting an SQLite timeout should cause one thread to sleep for a while and try again later. This is handled inside the SQLite library, but it just uses an ordinary system sleep, which hangs the whole app until the timeout expires.

I thought I would just leave the timeout at zero, which avoids SQLite itself trying to handle the error. I can do thread.sleep() myself which allows the other thread to proceed. This should be easy enough, but suppose the thread needing to sleep is the main thread. How do I sleep the main thread?


But putting that code in a thread or timer might be better.

You may want to pause the other thread instead, which would avoid having you app freeze on the user.

Or use a semaphore?

I’ll try the simple approach first - doing exponential backoff. So thanks Tim for the hint about sleeping any thread.

I take the point about the app freezing but the trouble is most actions in my UI involve some database activity. I’ll see how it goes.