Click here to Skip to main content
15,891,868 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hello,
I have a code:

C#
public class threading
    {
       Thread[] t;
       Thread monitor_q;
       ReadPackets rdpck;
       Networking net;
       general gen;
     
      
       public threading()
       {
          
           t = new Thread[250];       /////starts throwing stackoverflow exception from here onwards
           net = new Networking();
           gen = new general();
           monitor_q = new Thread(monitor);
           net.instantiate_5070();
           start_monitor_queue();
         
       }

     public void start_monitor_queue()
       {
           monitor_q.IsBackground = true;
           monitor_q.Start();

       }
 
 } 

Please advise,

Thanks,
- Rahul
Posted
Updated 6-Jan-14 20:55pm
v2

It is recommended that you use as few threads as possible, thereby minimizing the use of operating-system resources and improving performance. So your trying to create an array of 250 threads and your system do not have resource for them.
 
Share this answer
 
Comments
Rahul VB 7-Jan-14 5:36am    
Hello Sir,
I have to use these many threads. I initialized the threads in a different class. Now i implemented the IDisposable interface and then i did :

using(new Class())
{
/// perform operation with threads.

}
Is it correct?

Thanks a ton,
- Rahul
Raul Iloc 7-Jan-14 9:04am    
If you implemented IDisposable interface, all the resources created in your "Class" must be released in the Dispose() methods of the same "Class".

And regarding the threads it is not clear from your examples their links to class "Class", so in order to can help you I need more source code.
250 threads are way too much, except if you have a more-than-100-processors motherboard, which I doubt.

Moreover, there is a ThreadPool object that you can use which aims at the management of several threads running alltogether. Here are some links:
ThreadPool Class[^]
How to: Use a Thread Pool (C# and Visual Basic)[^]

Good luck.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900