Combobox Dropdown Caching

We have a VB.Net application that has about 80 unique ComboBoxes distributed across 15 Windows. Currently, when a window loads, ComboBoxes retrieves their contents directly from the SQL database.

This is rather inefficient, since the contents of ComboBoxes rarely change, so it makes sense to get all the values โ€‹โ€‹of the ComboBox drop-down list once when the program is launched.

I struggled to find working examples on the Internet of best practices in this regard. So that I do not invent the wheel, does anyone there have any words of wisdom or code fragments to point me in the right direction?

+4
source share
4 answers

Caching is definitely the way to go, using a hashtable, or something like that. If you can combine all the queries into a single SQL query, which returns multiple tables and gets everything in one call.

+2
source

The data can be serialized to the xml file that you load at startup, and fill in the combo boxes. You can then add the table to your database with one value, the last date when you updated your database, and if after the current date it starts your database queries to fill out the drop-down lists, and then update the XML file.

+1
source

This is very similar to what is contained in the application that I am developing. I created a static class with static DataTables in each combo box. When the application loads, it populates all the static data tables.

Example:

static public class GlobalDropdownData { static private DateTime Combo1Table; static private DataTable Combo1Table; static private DataTable Combo1Table; } 

Vb.net will be something like:

 Public Class GlobalDropDownData Shared Combo1DT As DataTable Shared Combo2DT As DataTable Shared Combo3DT As DataTable End Class 
+1
source

Yes, you can load all the search data at application startup, in a single call that returns multiple result sets. The Winforms application I inherited did just that, but the trade-off was that the startup time was terribly slow, since it took a few seconds to call the web service, which was made to retrieve the search data from the database to return all cached results, to execute. If this is a problem, you need to run an asynchronous call to the database / web service, so when executing the database code, more initialization work may happen. If you need to make sure that the data has been returned before the user completes a specific task, for example, by clicking on the button to display a screen with one or more of the lists requiring cached data, using one or more Winforms timers can help as well.

Another way to help performance might be to make a data access call in a separate thread, although in the project I was working on, I found other options sufficient to reduce startup time from about 10 seconds to less than 3 seconds without having to deal with multithreading difficulties.

0
source

All Articles