0

Here is the scenario: I have a dll which has method that gets data from db, depending on parameters passed, does various checks and gives me required data.

GetGOS_ForBill(AgencyCode)

In a windows application, I have listbox which list 500 + agencies. I retrieve GOS for each agency append to a generic list. If the user has selected all agencies (500 + for now), it takes about 10 min. to return data from the dll.

We though about background processing. But that doesn't reduce the time, other than user get to do other things on the screen. Considering multithreading.

Can anybody help me with this? What would be right approach and how can we accomplish with multithreading?

3
  • Use the Parallel class. Commented Jan 18, 2013 at 15:24
  • All depends on how that dll method is implemented if it will support multithreading or not. Commented Jan 18, 2013 at 15:27
  • Do you have example of parallel class? Also when we were writing the dll method, threading was not taken into consideration. Is there anything that we need to do specifically if we have to call a method using multi-threading? Commented Jan 18, 2013 at 15:32

1 Answer 1

4

By the way you ask I think you don't have much experience with multithreading and multithreading is not a topic to just be improvised and throw away via a Stackoverflow quesiton. I would strongly advice against using multithreading if you don't know what you're doing... instead of one problem you'll have two.

In your case the performance problem does not have to do with using threading to get a parallel workload but with correctly structuring the problem.

Right now you're querying each agency separately which is working fine for a couple of agencies but is degrading quickly. The query itself is probably fast, the problem is you're running that query 500 times. Instead of that why don't you try to get all the GOS for all the agencies in a single query (which is probably gonna be fast) and store that in memory (say a Dictionary). Then just retrieve the appropiate set of GOS when needed.

If the most usual case is a user just selecting a couple of them you can always establish a threshold... if the selected number is less than, say, 30 do each query, otherwise run the general query and retrieve from memory.

Sign up to request clarification or add additional context in comments.

4 Comments

Your understanding of my requirement is right too. By i do not get how the solution you suggested would help. Even if you have to place it in memmory, it still would need to take that 10 minutes. if i select all agencies right. I am open to other suggestions other than multithreading.
Nope. If it's a query to a database odds are a single query retrieving all the data will be much much faster than 500 queries retrieving subsets of the data. Now you're probably doing something like SELECT * from GOF where AgencyCode = xxx about 500 times... I suggest changing it to SELECT * from GOF and then reading all records and storing them in memory based on the agecy_code
That method is not just a simple select. There is a complicated business logic behind that method. It gets data data from multiple tables, based on certain other business requirements and returns a generic list. Even with this complicated process it is able to return the data with few seconds for a single agency. So the method is faster, no doubt. But it just takes time when we have to process all agencies.
Using multithreading won't help you either. Your client can launch 5 or 6 concurrent requests but the database server will handle them in its own way and the increase in performance won't be linear (i.e. you won't get results 6x faster but maybe 1.5x faster)... The fact that the method is faster does not change the fact that you're calling it 500 times. If you're able to write a method that does the same but for ALL the agencies you might see the performance of such a method is mabye 2 or 3 times slower than the original one... compare that with 500 execution of the original.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.