Click here to Skip to main content
15,868,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i want to project run the more than 100 work in project but when use 100 Thread,my program and form load is very slow and program is have interrupt.
i have the task but work slow,
what best way to do this ?

this my code:
C#
Thread[] thr = new Thread[100];
sensorTestThread[] inevestigationBox = new sensorTestThread[100];
 for (int i = 0; i < 100; i++)
   {
     inevestigationBox[i] = new sensorTestThread("192.168.16.254", 4000,i);
     thr[i]=new Thread(inevestigationBox[i].Connect);
     thr[i].Start();
   }


my data receive from socket is very important.
Posted
Comments
mosi98 31-Jan-15 1:56am    
i have more than 100 device that the data is vital
so have to run one thread for each device,because i have to check data received from each device continual
Sinisa Hajnal 31-Jan-15 2:36am    
Add your comment to the question, there is improve question link.

I would either make the queue in which devices send their messages and several (10? 20?) threads would work on them or if you don't have deviceID in the message, then make 100 queues with again smaller number of threads that would work on them.

If it is real time data exchange, then create smaller number of threads, but run the application on more then one physical computer that will receive data from some subset of your devices.
Richard MacCutchan 31-Jan-15 4:08am    
100 threads is always going to cause you problems because of the switching overhead. If you really cannot do it any other way then you need to get a more powerful mutli-core system.
Kenneth Haugland 31-Jan-15 4:50am    
If this is a requirement you should rethink your design. What you want to do is really not a good idea.
CPallini 31-Jan-15 6:06am    
Why do you need a thread per sensor? It doesn't look efficient, after all.

1 solution

i use the concurrentQueue and solve this and enqueue to queue from all thread
 
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