|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
MultithreadingI know this has been discussed a million times here but either I am not finding the right information yet or I just do not understand it. My problem: I am using VB.NET 2003. As part of my app, I have a Listview that has a list of directories in the left column. In the right column I want to put the total size of each folder. So, I've wrote the function to return each size and I can get it to total each folder line by line. However, this takes ages! So, I want to fire off a thread for each folder and total them all at the same time. This is where my problem is. I can fire off the threads but only if I declare each thread seperately. As I do not know how many threads I need, I want to create a "Thread Array" of some sort. i.e. Thread(#).Start etc. etc. This I do not know how to do. But, worse still, I wrote a function that totals up the sizes and returns a value with the total. This works by passing the path name as a string to the function. When I try to do this via a thread I get an error telling me basically that you cannot pass arguments to a function in a thread. So I am stuck! As a summary, what I want to do is: - Create x number of threads based on how many rows are in the listview. - Fire them all at once (to run together) and pass the path as an argument. Is this even possible? If so, any help would be most appreciated. Thanks, Hugh. "Hugh Janus" <my-junk-acco***@hotmail.com> schrieb I don't have a solution, but I think it doesn't make sense to use one thread> My problem: I am using VB.NET 2003. As part of my app, I have a > Listview that has a list of directories in the left column. In the > right column I want to put the total size of each folder. So, I've > wrote the function to return each size and I can get it to total > each folder line by line. However, this takes ages! So, I want to > fire off a thread for each folder and total them all at the same > time. This is where my problem is. per directory. This would slow everything down a lot because the HD's read/write head would have to jump even more if you switch between directories all the time due to multithreading. If you wanted to create an array of threads, you would declare it like any other type of array: dim t() as thread or dim t as thread() Or use an arraylist. "Parameters and Return Values for Multithreaded Procedures": http://msdn.microsoft.com/library/en-us/vbcn7/html/vaconParametersReturnValuesForFreeThreadedProcedures.asp Armin Yes, I understand about the issue with the drive heads although this is
not so much of a problem for me because the data is stored on a striped array which will help performance. I read that a threadpool might help me. Is this the case? Hugh,
Let me as another try to tell you because Armin told it right while the disk was just one example. Mutltithreading cost forever more processing time. Only if the processes of the threads are independend from each other than you can get a faster troughput time. By instance downloading more files from interenet where there are more senders from which the connection is slower than the connection of the receiver. However, than still is the used processing time more. (Don't forget however that most used time by a computer is idle time). I hope that this gives an idea. Cor Cor,
I understood what Armin said. His point was that using multiple threads would cause excessive CPU cycles because of disk activity. I said that this would not be such a problem because I am using a raid-10 stripe set on a high powered SCSI system. Considering there would never be more than 10 threads (at a maximum) I don't see that this would be a great problem for me. Bearing in mind that doing a large folder on it's own takes no more than about 45 seconds anyway. Using some sort of threadpool or multiple threaded code would save me time during execution. So I am hoping someone can help me out with the code/understanding of this and if in the end it does work out a problem because of the CPU it would be a lesson that I have learnt anyway and would be a good record in the archive for future people with a similar question. Hugh Sorry, I used a colleagues PC to post this instead of mine, that is why
my reply has the wrong name! Sorry D, but now you are gonna get spam because your email address is now public. oops. On a single processor computer, all threads use the same processor. If your
application has to wait for the threads to finish, you would be better off without threads. In Windows form applications requiring a user interaction, I havent' found much use for threads except for something like printing or writing to a large file to a disk. There are probably some other speciality uses of threads but I suspect fopr the most part, threads are very over used by a lot of non-pros. -- Show quoteHide quoteDennis in Houston "Hugh Janus" wrote: > Sorry, I used a colleagues PC to post this instead of mine, that is why > my reply has the wrong name! > Sorry D, but now you are gonna get spam because your email address is > now public. oops. > >
Hepl! No accessible 'Main' method with an appropriate signature was found ...
Q: primary key OK....forget the code...how about some pointers? API confusion "Global" Class Library: Best Practices? Threading question.... Problem with objects and automatic numbering in VB.NET executing a .dll? Detect if user is logged in Setting Individual Pixel Colors in VB 2005 |
|||||||||||||||||||||||