Results 1 to 5 of 5

Thread: [RESOLVED] multithreading function question

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2009
    Posts
    53

    Resolved [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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: multithreading function question

    Quote Originally Posted by zeekapitein View Post
    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.

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2009
    Posts
    53

    Re: multithreading function question

    Quote Originally Posted by jmcilhinney View Post
    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

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: multithreading function question

    Yeah, what you were suggesting was very wrong. You can just do this:
    vb.net Code:
    1. Dim rng As New Random
    2. Dim filePaths = IO.Directory.GetFiles(folderPath).OrderBy(Function(s) rng.NextDouble()).Take(5).ToArray()
    3.  
    4. For i = 0 To 4
    5.     PictureBoxes(i).LoadAsync(filePaths(i))
    6. 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.

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2009
    Posts
    53

    Re: multithreading function question

    Great thnx!!!

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
  •  



Click Here to Expand Forum to Full Width