C #: Preloading forms in a separate thread

I have some forms that take some time to open, because they currently get some things from the database in the load event handler.

Is it possible to somehow upload forms to a separate stream and show them to the user when this is done?

If you load them in such a way that a load event handler is not possible, perhaps having an IPreloadable interface can do the trick using the Preload method and then move the contents of the slow boot into it. If you can show the form from a separate thread, which ... I think I will need to use Invoke or something like that?

+4
source share
1 answer

If you load different forms into different streams, you need to be very careful when you make calls between forms - you will need to use Control.Invoke / BeginInvoke everywhere.

Please note that although each top-level window can work in a different thread, all controls in the window must be created (or rather, they must have their own descriptor) in the stream for this window.

Why not download the database information in the background, and then when this is over, you can create the actual form and display it? (Until then, you can either change the wait cursor, or perhaps put a message about the status of "Loading data ...".

+2
source

All Articles