Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
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 or parallel class.

Can anybody help me with this? What would be right approach and how can we accomplish this?
Posted
Comments
BC @ CV 18-Jan-13 11:19am    
Keep in mind multi-threading only speeds up processing if you have multiple CPUs.
Devender Pratap 25-Jan-13 2:25am    
it's not working properly

1 solution

Multithreading or parallel may or may not speed things up - it can actually slow things down because of the processing overhead in setting up the thread / tasks and allocating separate memory space for them. In addition it depends what else is going on - if each thread needs to talk to SQL then that will potentially use two cores per thread.

The first thing I would do is look at what you have, and start timing it. (Use the Stopwatch class) Try to find which part of the operation is taking time, it may be that you can make a simple change which cuts it dramatically. For example, if you are doing a trip to your DB for each item going into the list, then you may find it a lot quicker to do a single trip then sort the data out afterwards. At least if you have worked out how long each part takes, you can both target your changes, and quantify them as to whether they are worthwhile solutions or not.

(I had a list which loaded from a database on startup, and it took two and half minutes to load 1000+ items using a background task and a splash screen. By timing what was wasting time, I got it down to 12 seconds for 30,000 items, and dumped the splash)
 
Share this answer
 
Comments
SandhyaPillai 18-Jan-13 11:44am    
For a single agency method takes only few seconds to get the required result. Method has a complicated business logic, inspite of that it takes only few seconds.
Method is faster, no doubt. Now the quesyion is how I can improve the timing if multiple agencies are selected? User can select 1 to all (500 + agencies). Problem arises if they choose to get data for all. I am running on .net3.5, parallel class is not an option. I was just reading up on that since another developer suggested that. Looks like it is available oly in 4.

There is no requirement forcing me to use multithreading, neither I know much about it. I am just looking for the right approach.
OriginalGriff 18-Jan-13 12:20pm    
And those seconds mount up! :laugh:

Have you considered "cheating"? Have a list of "to be fetched" agencies and a background task that runs though fetching them if they aren't already. If the user selects an agency then check if it is fetched, and if not it goes to the head of the list to be fetched next. That way, you are using the users time when he is deciding who to select to do the actual work, and hopefully, he should never have to wait more than a few seconds before the data is ready to go. (This does assume that the selection logic doesn't change anything until the user commits to it - but that would be a nasty way to work anyway.)
SandhyaPillai 18-Jan-13 13:47pm    
yep :) seconds mount up to min.

waiting for others input........thank you very much.
OriginalGriff 18-Jan-13 14:01pm    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900