Show a splash screen while a database connection (that might take a long time) runs

前端 未结 2 923
野趣味
野趣味 2020-12-18 05:51

I am trying to show a splash screen, and not freeze up the application, while it connects to a database. Normal connections (to MSSQL via ADO) take about 300 msec, and this

相关标签:
2条回答
  • 2020-12-18 06:34

    There are several methods for inter-thread communication. I usually use Window's messages. First I define custome message and message handler in a form. Then when I need to inform main thread from custom thread, I use PostMessage function to send notification.

    Small tutorial here.

    You can also use library for threading, eg OmniThreadLibrary.

    0 讨论(0)
  • 2020-12-18 06:51

    Because of the known limitation that every thread must use it's own ADO connection (ie you cannot use a connection object created in other thread), the only option I can think of is create a thread that will make a connection to database, and, after the connection is established or timeout is reached, signal the main thread about the event and close/destroy the connection. The main thread can in the meantime display splash or progress, waiting for a message from that thread. So, you eliminate the case with wrong password or unreachable host. There is a reasonable assumption, that, if the second thread could connect, the main thread would be able to connect right after.

    0 讨论(0)
提交回复
热议问题