Converting a nested loop to use multithreading?

  • Thread starter Thread starter Richard Aubin
  • Start date Start date
R

Richard Aubin

Hello all,

I have the following nested loop structure that I would love to convert to x
amount of threads:

For i = 0 To 100
For j = 0 To 100
For k = 0 To 100
Console.WriteLine("k = " & k)
Next
Console.WriteLine("j = " & j)
Next
Console.WriteLine("i =" & i)
Next

This process is based on existing code that I have that is taking well over
1 hour to complete.

Could someone provide me with example code to convert this to
multithreading, say 10 threads at once?
 
Hi Richard,

I don't have the code, but this raises an interesting question to me.

Doing 10 things simultaneously isn't necessary quicker and may actually be
slower... right or wrong?
Unless in each thread there is some latency time that the thread must wait
for I/O or something that another thread might be operating. Because unless
you have more than one processor, nothing actually happens at the same time,
just the process's time is divided per thread... am I right on this?

Sorry I don't have the code.. but also wanted to know an answer to my
question about your question. :)

Shane
 
In that case, Chapter 19 of the Wrox "Professional VB.NET" book has code
that might be of use on how to do threading and thread pooling.

you can probably download the code from
www.wrox.com

maybe it would give you and idea.

HTH,

Shane
 
Hi Shane,

That is exactly what I'm looking for.

Now all I have to do is dissect their code and apply it to my program.

Thanks!
 
It is a pretty decent book Not bad for a reference... If you decide to buy
a copy--for sure buy online..the book is like $60 in Books a million but if
you get there discount card and order online it is at least half that price.

Glad to help you,

Shane
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top