I have a Winform application that creates 5 threads to connect and get to a database on a slow connection (90 seconds for some queries). Each thread has its own example of a class to run SQL queries. When the queryed data is retrieved, the main thread is notified by an event removed from the class that runs the query. After receiving the event, various components of the main thread are updated such as display item or data holding data for later use.
Everything works great ... but I am not happy. I think it should be done in a different way, but I'm not sure how to
Below I am currently setting each thread:
string ConnectionString = @ "data source = mySrv; initial catalog = myTbl; connect timeout = 30; uid = Pwd = mipvand "; // thread # 1 SQL_Requests ReasonRequests; Thread Rezinhaith; ReasonRequests = new SQL_Requests (); ReasonRequests.ProcessFinished + = New SQL_Requests.ProcessFinished (ReasonRequests_Completed); Reason_Thread = New thread (ReasonRequests.ExecuteQuery); ReasonRequests.DBQueryString = "Select from ReasonTable *, Where Stirling = Welcoming" ReasonAx DBC connection = connection string; // Thread # 2 events of SQLRUV; Thread event tag; EventRequests = new SQL_Requests (); EventRequests. ProcessedFilter = New SQL_Requests.ProcessFinished (EventRequests_Completed); Event_Thread = New thread (EventRequests.ExecuteQuery); EventRequests.DBQueryString = "Choose from EventTable * where somefield = somevalue" EventRequests.DBConnection = ConnectionString;
Itemprop = "text"> Instead of spinning your sources, you should take a look as an asynchronous method to execute the questions
Did you mention that your connection is slow, is it a low bandwidth connection or a high latency connection? If for many years the data is being returned slowly due to inadequate bandwidth firing, then things will get slower, if there is a delay in many questions at one time, accountability can improve.
If you are performing a group of related questions, then you should consider grouping them in one command or grouping it on the server using an stored procedure. Es. You can get additional results set by using the NextResult method on SqlDataReader.
Comments
Post a Comment