Recommended way to open a table in a DataModule within a thread?

Recommended way to open a table in a DataModule within a thread?

We've got a DataModule with a bunch of tables on it, and several of them are opened at program startup and left open for the duration of the program.

The data is coming from a DB server somewhere (ie., not locally).

A few are quite large and take a long time to load.

Other than local caching, we're thinking it might work well to simply run the slower-loading queries in a separate thread. I know there are issues running threads in forms, and DMs are basically forms although they don't interact with the screen. Anyway, we're getting weird errors, so I think we're missing something.

Can someone please post a snippet of code that shows how to do a simple TDataSet.Open; call inside of a thread?

We'll also need a simple flag that's set when it's ready to use, although I don't expect any major race conditions. It's only going to be run once when the app starts up.

Comments

  1. David Schwartz i had a problem of slow data reading in SQL server 2008 . I had problems with locate and more. I had many computers.
    Some worked OK.
    so i wrote a test program to do with a few option to test the DB.
    Although it is specialize to my need it proved writing the
    program differently speed the process.
    It was with D7. I can share it with you (source).

    I found that the electronic switches !!! on some junction !!! and my software are the problem,both.
    In any case if you want i can send it to you
    without too many explanations. (since it was written many years ago).
    get in touch : limelect at gmail dot com

    it will take a day or more since it is PASSOVER

    ReplyDelete
  2. David Schwartz if you are working with static tables, why aren't you caching them to local tables? why do you need to download the data on every start? sqlite could be of help in this scenario, once in a while you can check if something changed in the server table and update it.

    ReplyDelete
  3. Well ... after some poking around, it turns out that caching them was quite simple. Much simpler than putting the queries into threads. And we got a HUGE speed-up. So I appreciate all of the suggestions and comments about threading, but it looks like we've solved the problem without it. :-)

    ReplyDelete

Post a Comment