-
Aug 12th, 2012, 03:58 AM
#1
Thread Starter
Member
[RESOLVED] multithreading function question
Hi
Can somebody give me some help please
my problem:
mainform:
I'm looping a function Xtimes
Function
In the function i'm starting a new thread
Dim newThread As New System.Threading.Thread(AddressOf AMethod)
in the sub() i'm adding a picturebox to the mainform.
=> so the code ads for example 5 pictureboxes and starts 5 threads ... How can I stop all the threads?
Is this the the correct way of programming????
thnx
-
Aug 12th, 2012, 04:50 AM
#2
Re: multithreading function question
Originally Posted by zeekapitein
Is this the the correct way of programming????
It sure doesn't sound like it. How about you explain to use what you're trying to achieve instead of how you're trying to achieve it? If we don;t know why you're doing this then we can't really tell you whether it's the best option or not. That said, it's hard to imagine what you've described could be the best option for.
-
Aug 12th, 2012, 06:09 AM
#3
Thread Starter
Member
Re: multithreading function question
Originally Posted by jmcilhinney
It sure doesn't sound like it. How about you explain to use what you're trying to achieve instead of how you're trying to achieve it? If we don;t know why you're doing this then we can't really tell you whether it's the best option or not. That said, it's hard to imagine what you've described could be the best option for.
Sorry
I will try to explain what I try to achieve.
I have 1 folder with +/-100 images in it.
The program loads the folder
the the user choses to load X (some number) photo's.
So I have one function that random selects for example 5 photo's
Function selects photo and adds a photobox to the main form.
It want to achive it with multhithreading beceasue I'm trying to speed up the process.
Sorry for my bad english . I would be happy if you have tutorial on dynamicly creating threads.
Thnx for the help
-
Aug 12th, 2012, 06:29 AM
#4
Re: multithreading function question
Yeah, what you were suggesting was very wrong. You can just do this:
vb.net Code:
Dim rng As New Random Dim filePaths = IO.Directory.GetFiles(folderPath).OrderBy(Function(s) rng.NextDouble()).Take(5).ToArray() For i = 0 To 4 PictureBoxes(i).LoadAsync(filePaths(i)) Next
This assumes that you already have the PictureBoxes in an array.
That said, given that they are local files, I'm not actually sure that LoadAsync would provide any real improvement over Load. Exactly how long does it take to load 5 image files synchronously anyway? I'm guessing not much more than a second, if that.
Last edited by jmcilhinney; Aug 12th, 2012 at 06:32 AM.
-
Aug 17th, 2012, 02:38 AM
#5
Thread Starter
Member
Re: multithreading function question
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|