Link to home
Start Free TrialLog in
Avatar of Millkind
MillkindFlag for Afghanistan

asked on

Pool Threading with changing parameters

emailstuff(5) is changing with the x but not changing in the threads.

        Dim emailstuff() As String = {"Name", "campusbox", "recievedate", "Shippingmethod", "Trackingnumber", "Packagetype", "Noticelevel", "", "emailaddress", "originator"}
        For x As Integer = 1 To 10
            System.Threading.ThreadPool.QueueUserWorkItem(AddressOf sendEmail, emailstuff)
            emailstuff(5) = x
        Next

Open in new window

Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Pass EmailStuff(x) as the parameter:

For x As Integer = 1 To 10
            System.Threading.ThreadPool.QueueUserWorkItem(AddressOf sendEmail, emailstuff(x))            
        Next

Open in new window

Avatar of Millkind

ASKER

I want each thread to have different parameters. Not just send the on parameter over and over.  Also the sub requires an array not a string.
Change sendEmail to accept a string and just pass emailstuff(x)

this will change every time because of the array with the counter.

The other thing you can do is pass in X and reference the array globally, but I wouldn't go that route.
ASKER CERTIFIED SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
All the items in emailstuff will be different in each thread.  I only changed the 5th one for this as a test to see how to do it.  I am new to threading and the articles and tutorials were very confusing.  I believe i understand what a thread pool is in theory but not in practice.  Like why can't I change the input for each pass in the for loop?  Im going to work with the Module now.
With a little tweaking it works wonderfully.  Also by doing the tweaking I have learned a little bit about threading.  It is easier to see it done then read about it sometimes.

Thanks,