Link to home
Start Free TrialLog in
Avatar of jayrod
jayrodFlag for United States of America

asked on

split arraylists into multiple arraylists?

I have a custom email campaign system that is limited to sending 200 emails per send.  I have an arraylist full or subscriber emails.  If I have a list of 407, how can I break that up into 3 or 4 seperate arrayLists?  Is this even the best way of going about this task?

Right now I have:

For i = 0 To (alSubscribers.Count()-1)
  '//get the message
  '//setup the email

  '//send the message to the first subscriber

Next i

And this works just fine, up to the 200th subscriber since my ISP restricts relays to 200 per send.

Thanks very much for your help!  If it makes a difference, I am running this on a background thread.

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of strickdd
strickdd
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
Avatar of jayrod

ASKER

Thanks - that seeme dto do the trick.  You even got the syntax right :)

However, this has now spawned into another (threading) question.  The list is 407 and it sent to 290 of them.  It seems that the thread was killed or died at 290.  Is there a way to check the thread in the same code that you sent to make sure it is still running, and if not - pick up where it left off?

For example I have:

For i = 0 to (alSubscribers.Count()-1)
  '//check thread
  If NOT Thread.IsAlive (or someting?) '//check the thread
    '//do something here to pickup at i value?
  End If

  If (i Mod 200) = 0 Then
     Thread.Sleep(1000)
  End If


Thanks for your help!!
Avatar of jayrod

ASKER

BTW - if you can't tell this is my first attempt at Threading!
Avatar of jayrod

ASKER

I found this - would something like this solve my problem If I do this after I start the thread:

myThread.Start()

Do While Not myThread.ThreadState = System.Threading.ThreadState.Stopped
  Thread.Sleep(100)
Loop


Thanks again!
The thing is you want to avoid threading as much as possible. The code I gave you just pauses the thread that is currently being processed for 1 second. If you gett into threading a .Net web application then you can encounter some serious problems/anomalies.

What is probably happening is the thread stays alive too long and times out. So if you shorten the wait time to something like:
.Sleep(200) that might help.
Avatar of jayrod

ASKER

Thanks! I will give that a try - hopefully it works!