The first point is that if you explicitly create such threads, you are not using the thread pool. The CLR is committed to creating all of these threads, although ultimately it will create too much and drag out. 1000 explicit threads are too many.
Are you trying to do this on another thread because you want this to happen asynchronously or because you really want multiple threads to send?
If the first, try something like:
ThreadStart ts1 = new ThreadStart(sendMails); Thread thread1 = new Thread(ts1); thread1.Start(); public void sendMails() { foreach (DataRow dataRow in dataTable.Rows) {
If you feel that sending performance will be improved with multithreading, you need to manually reduce the number of threads created at any time, or use the .Net thread pool, since this will allow you to queue that will be blocked until the thread becomes free . This is certainly preferable to creating downloads of explicit threads.
Rob levine
source share