Click here to Skip to main content
15,898,939 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I use this code
but it is slow and use more cpu
so
i want faster way
but how i can do it?
( i want crate a cracker. becasue of this i need much thread )
my code

C#
public void Start()
{ 
 
for (int i = 1; i < 150; i++)
{
Thread reqThread = new Thread(new ParameterizedThreadStart(Test));


reqThread.Start(i);

}
 
}
 
 
Public void Test ( object i)
{
 
Try{ 
    SetProxy
            Connect 
                         Send
                               Response 
   }
 
  catch
 {
    Test(i)
} 
 
} 
Posted
Comments
Ziee-M 11-Aug-14 7:37am    
you can't increase a thread speed, but you can increase priority althought its not recommended.

the only way to increase speed is to optimise your code or use a better Computer (processor).
Ziee-M 11-Aug-14 7:48am    
I just watched the code and the approch is wrong ! you are instanciating 150 thread ! thats useless (totally wrong !). instead, create a limited number of thread and make them do the job.
Why? because each thread can be executed by a processor, in your PC you don't have hundred of processor (8 in the best scenario for a Personl computer)

I recommend you to read a little about threads and their life cycle, computer architecture...

1 solution

To begin with thread speed is an relative concept and depends on your CPU (starting 150 threads with complex processing can be cumbersome, less is more!).
In general, bad threading logic can easily result in slowing down application... and to some odd exceptions.

Three things come to mind when I look at you example_
1. Test method jumps out as really bad.
Inside catch block you don't handle exception, you just recursively repeat call to Test method, that can result in (semi-)endless loop.
2. If by cracker you mean web crawler then network speed can be a factor.
3. Perhaps there are shared resources (properties) between threads which aren't properly shared or are locked too long.

Use perfmon tool for pinpointing bottlenecks in you application.

Good luck!
 
Share this answer
 
v3

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