I have an winform application that creates 5 threads to connect to and retrieve information from a database on a very slow connection (90 seconds for some queries).Each thread has it's own instance of a class for performing sql queries. When the queried data has been retrieved the main thread is notified by an event fired from the class running the query. After receiving the event various components of the main thread are updated such as display items or just a datatable holding data for later use. The queries are repeated at various intervals depending on the type of information that they are querying.
Everything works great...but I am not happy. I feel that it should be done a different way, but I am not sure which way.
Below is how I currently set up each thread:
string ConnectionString = @"Data Source=mySrv;Initial Catalog=myTbl;Connect Timeout=30;UID=sa;pwd=mypwd";
//thread #1
SQL_Requests ReasonRequests;
Thread Reason_Thread;
ReasonRequests = new SQL_Requests();
ReasonRequests.ProcessFinished += new SQL_Requests.ProcessFinished(ReasonRequests_Completed);
Reason_Thread = new Thread(ReasonRequests.ExecuteQuery);
ReasonRequests.DBQueryString = "select * from ReasonTable where staralingment = goodalignment"
ReasonRequests.DBConnection = ConnectionString;
//thread #2
SQL_Requests EventRequests;
Thread Event_Thread;
EventRequests = new SQL_Requests();
EventRequests.ProcessFinished += new SQL_Requests.ProcessFinished(EventRequests_Completed);
Event_Thread= new Thread(EventRequests.ExecuteQuery);
EventRequests.DBQueryString = "select * from EventTable where somefield = somevalue"
EventRequests.DBConnection = ConnectionString;
each Thread.start are at different intervals.
any recommendations?