[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
Re: multithreading function question
Quote:
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.
Re: multithreading function question
Quote:
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
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.
Re: multithreading function question