I have some forms that takes a bit of time to open because they currently get some stuff from a database in their Load event handler.
Is it possible to somehow load the forms in a separate thread and show them to the user when that is done?
If loading them so that the Load event handler is fired is not possible, maybe having a IPreloadable interface might do the trick with a Preload method, and then move the slow loading contents into that. If it is possible to show the form from a separate thread that is… guess I would need to use Invoke or something similar?
If you load different forms on different threads, you’ll have to be very careful when you make calls between the forms – you’ll need to use
Control.Invoke/BeginInvokeall over the place.Note that while each top level window can run on a different thread, all the controls within a window must be created (or rather, they must have their handle created) on the thread for that window.
Why not load the database information in the background, and then when that’s finished then you can build the actual form and display it? (Until then you might either want to change to a wait cursor, or possibly put a “Loading data…” status message somewhere.