WebThreads

Hello all,

I have a cooperative WebThread that performs database inserts and updates a progress bar to keep the user informed of progress of the operation (via UserInterfaceUpdate).

The UI remains responsive as the thread runs until completion (all records are inserted into the database table and the progress bar reports the progress accurately).


I then created a second cooperative WebThread that processes a second queue of db inserts.

It uses a second (discrete) connection to the db.
It updates a different table to the first thread.

I run both threads together:

  • initially each having Low Priority (1)
  • again with each Normal Priority (5)

During both attempts the progress bars progress for a while then eventually freeze.

Generally, one of the threads completes its db inserts (even though the progress bar does not confirm this) the other only gets part way through.

The app doesn’t crash in the IDE nor browser, however requires restarting, maybe some unhandled exception I have not trapped which I will investigate. No errors either with the try/catch on db inserts.

If I run each thread separately until completion they work fine, but that is not really the point of the exercise.

Should this approach currently work for web?

Thank you in. advance.

Kind regards, Andrew

If this is SQLite, you either have to turn on WAL or protect your database operations with a Semaphore, CriticalSection, or Mutex.

Hello Tim,

It’s MySQL/MariaDb! and I’m using cooperative threads at present. Each thread also has it’s own db connection.

Kind regards, Andrew

Are you sleeping your insert threads periodically to allow the other threads of your app (sessions as well as the multiple database threads) time to perform their own operations? If not, you’re likely seeing this because the session threads aren’t able to get time to update the UI, which can lead to session disconnects.

Without some code to inspect, it’s hard to say what the issue might be, but it sounds like you’re starving your threads.

Thank you Anthony, will update them and do some more testing.

1 Like

Thanks @Anthony_G_Cyphers, sleeping periodically did the trick. Just some “trial and error” on the how often to sleep without hurting performance or breaking the session.

Kind regards, Andrew

1 Like

Glad to hear it!