Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0 .NET3.5 multithreading , +
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 18-Jan-13 5:09am
Comments
BC @ CV at 18-Jan-13 11:19am
   
Keep in mind multi-threading only speeds up processing if you have multiple CPUs.
Devender Pratap at 25-Jan-13 2:25am
   
it's not working properly

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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)
  Permalink  
Comments
SandhyaPillai at 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 at 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 at 18-Jan-13 13:47pm
   
yep :) seconds mount up to min.
 
waiting for others input........thank you very much.
OriginalGriff at 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)

  Print Answers RSS
0 BillWoodruff 309
1 CPallini 300
2 Sergey Alexandrovich Kryukov 290
3 George Jonsson 274
4 Gihan Liyanage 230
0 OriginalGriff 4,895
1 CPallini 4,010
2 Sergey Alexandrovich Kryukov 3,514
3 George Jonsson 2,826
4 Gihan Liyanage 2,386


Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 18 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100