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!
LVL 3
jayrodAsked:
Who is Participating?
 
strickddConnect With a Mentor Commented:
If you want you can pause the sending after every 200 e-mails for a second.

For i = 0 To (alSubscribers.Count()-1)

  if (i MOD 200) = 0 then '//not sure of syntax for VB but it is i%200 in C#
     System.Threading.Thread.Sleep(1000)
     '//This causes a 1 second delay before moving on to the next code
     '//This means every 200 e-mails it will wait 1 second before sending another.
  end if

  '//get the message
  '//setup the email

  '//send the message to the first subscriber

Next i
0
 
jayrodAuthor Commented:
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!!
0
 
jayrodAuthor Commented:
BTW - if you can't tell this is my first attempt at Threading!
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
jayrodAuthor Commented:
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!
0
 
strickddCommented:
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.
0
 
jayrodAuthor Commented:
Thanks! I will give that a try - hopefully it works!
0
All Courses

From novice to tech pro — start learning today.