Wrox Home  
Search P2P Archive for: Go

  Return to Index  

ado_dotnet thread: Lists of Lists


Message #1 by "Marl Atkins" <marl@s...> on Fri, 27 Sep 2002 19:20:16
Hi:

I'm trying to create about 30 threads of components, each to send out x 
EMails.

I've got an ArrayList of All EMial Addresses, the number is iAllRecs.
So, iRecsPerThread = iThreads/iAllRecs;

I'm trying to iterate through the emails and create ArrayLists, each 
containing iRecsPerThread EMail addresses (or less on the last one).

I need to create the ArrayList, fill it and send it off to the threaded 
object. 

My problem is with declaring the ArrayLists that I'm trying to send. I 
seem to only be able to create one. I even tried creating an AllArrayLists 
ArrayList and that didn't work either.

Really, I don't care if I use an ArrayList or something else. I just need 
to split the "All" list up into iThreads lists containing iRecsPerThread 
EMails each (or less), and get each list sent off to another function 
(probably in another object).

How can/should I do this?

Message #2 by "David Garner" <dgarner@g...> on Sat, 28 Sep 2002 02:14:01
ArrayList alForThreads = new ArrayList();
ArrayList alSubList = new ArrayList();

int count = 0;
do
{
    for (int x = 0; x < iRecsPerThread; x++)
    {
        alSubList.Add( emailaddress[count] );
        count++;
        if (count > iAllRecs) break; // takes care of last set
    }
    alForThreads.Add( alSubList );
    alForThreads = new ArrayList();
}while( count < iAllRecs)

// at this point you will have and array list of array lists

Is this what you were looking for?  It could be a little off.  I'm lost 
without intellisense.


> Hi:

> I'm trying to create about 30 threads of components, each to send out x 
E> Mails.

> I've got an ArrayList of All EMial Addresses, the number is iAllRecs.
S> o, iRecsPerThread = iThreads/iAllRecs;

> I'm trying to iterate through the emails and create ArrayLists, each 
c> ontaining iRecsPerThread EMail addresses (or less on the last one).

> I need to create the ArrayList, fill it and send it off to the threaded 
o> bject. 

> My problem is with declaring the ArrayLists that I'm trying to send. I 
s> eem to only be able to create one. I even tried creating an 
AllArrayLists 
A> rrayList and that didn't work either.

> Really, I don't care if I use an ArrayList or something else. I just 
need 
t> o split the "All" list up into iThreads lists containing iRecsPerThread 
E> Mails each (or less), and get each list sent off to another function 
(> probably in another object).

> How can/should I do this?

Message #3 by "Marl Atkins" <marl@s...> on Fri, 27 Sep 2002 21:38:14 -0400
Hi David:

Thanks for the help.

Yea that was real close.

Where you've got the do, I've got another for loop that iterates through all
the records:
My problem was that inside the if, I put:
ArrayList EMails = new ArrayList(100);
It was already declared, so the compiler didn't like it.
I just had to figure out that I could reinstantiate it w/out redeclaring it
(as you pointed out).

It looks like your code would work too and it's nice to see how you used the
do while.
I think it's even cleaner than mine:-)

Thanks again for the help.

if(iAllRecs > 0 && iAllRecs > 0)
{
	iRecsPerThread = iAllRecs/iThreads;
	for(int i=0; i<iAllRecs; i++)
	{
		if(x==0)
		{
			EMails = new ArrayList(100);
		}
		EMails.Add(arEMailsAll[i]);
		x++;
		if(x>=iRecsPerThread - 1)
		{
			SendEMails(EMails);
			x = 0;
		}
	}
}

-----Original Message-----
From: David Garner [mailto:dgarner@g...]
Sent: Saturday, September 28, 2002 2:14 AM
To: ADO.NET
Subject: [ado_dotnet] Re: Lists of Lists


ArrayList alForThreads = new ArrayList();
ArrayList alSubList = new ArrayList();

int count = 0;
do
{
    for (int x = 0; x < iRecsPerThread; x++)
    {
        alSubList.Add( emailaddress[count] );
        count++;
        if (count > iAllRecs) break; // takes care of last set
    }
    alForThreads.Add( alSubList );
    alForThreads = new ArrayList();
}while( count < iAllRecs)

// at this point you will have and array list of array lists

Is this what you were looking for?  It could be a little off.  I'm lost
without intellisense.


> Hi:

> I'm trying to create about 30 threads of components, each to send out x
E> Mails.

> I've got an ArrayList of All EMial Addresses, the number is iAllRecs.
S> o, iRecsPerThread = iThreads/iAllRecs;

> I'm trying to iterate through the emails and create ArrayLists, each
c> ontaining iRecsPerThread EMail addresses (or less on the last one).

> I need to create the ArrayList, fill it and send it off to the threaded
o> bject.

> My problem is with declaring the ArrayLists that I'm trying to send. I
s> eem to only be able to create one. I even tried creating an
AllArrayLists
A> rrayList and that didn't work either.

> Really, I don't care if I use an ArrayList or something else. I just
need
t> o split the "All" list up into iThreads lists containing iRecsPerThread
E> Mails each (or less), and get each list sent off to another function
(> probably in another object).

> How can/should I do this?

---
ASP.NET Distributed Data Applications
This book will inspire you with a range of ideas on how data
can be used to drive Web applications, and how that data can
be most effectively utilized at each level of the design.
Inefficient data use leads to the sort of slow, unresponsive
Web applications that nobody enjoys using. By making good use
of both server and client-side code, we can solve these
problems. This book will arm you with the techniques you need
to build Web applications that fly.
http://www.wrox.com/ACON11.asp?ISBN=1861004923


  Return to Index