I'm aware that the code I'm currently using is far from perfect. I'm not even sure if it does exactly what it is supposed to do, but I'm trying to do the following:
My Resources class, loads several tables from the database inside the application. This is static data that doesn't change such as a list of Countries for example. The basic idea behind this, is to run all the queries into seperate threads to prevent the application from hanging while the data is loading. I'm using the following code for that:
Expand|Select|Wrap|Line Numbers
- public void Load()
- {
- // Configure the Progressbar.
- ConfigureProgressBar();
- // Create for each method a new thread.
- new Thread(new ThreadStart(LoadActivityActions)).Start();
- new Thread(new ThreadStart(LoadActivityCategories)).Start();
- new Thread(new ThreadStart(LoadAssignmentStatus)).Start();
- new Thread(new ThreadStart(LoadCompanyStatus)).Start();
- new Thread(new ThreadStart(LoadCountries)).Start();
- new Thread(new ThreadStart(LoadDegrees)).Start();
- new Thread(new ThreadStart(LoadExternalStatus)).Start();
- new Thread(new ThreadStart(LoadIdentificationAction)).Start();
- new Thread(new ThreadStart(LoadInternalStatus)).Start();
- new Thread(new ThreadStart(LoadOfferStatus)).Start();
- new Thread(new ThreadStart(LoadPersonCategories)).Start();
- new Thread(new ThreadStart(LoadReport)).Start();
- new Thread(new ThreadStart(LoadSalesStatus)).Start();
- new Thread(new ThreadStart(LoadSectors)).Start();
- new Thread(new ThreadStart(LoadTargetStatus)).Start();
- while (this.ProgressBar.Value != this.ProgressBar.Maximum)
- {
- Thread.Sleep(0);
- }
- }
Or am I completly using the Thread system in a wrong way ?