Click here to Skip to main content
15,881,139 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Dear friends
i am using thread in c# programming and how to use all RAM Processor in c# application with thread .
help me .
Posted
Comments
Sergey Alexandrovich Kryukov 26-Dec-14 2:22am    
Why?!
—SA
Sanket Saxena 26-Dec-14 2:24am    
May i ask why you want to do this?

This is incredible. We already had a number of questions where people see that their applications use, by their opinion, too much of CPU and want to reduce this amount. I don't know why. And now you are asking, like some other inquirers, honw to use all CPU; probably it means 100%.

I have no idea why anyone would need it. Anyway, nearly always, if some manages to use about 100% CPU in one application, it typically means that this application does something extremely stupid. However, if this is not UI application and when all other applications are inactive (say, all threads of other applications are in wait state, which is a normal thing; it happens with all UI application when then don't do any background processing and nobody sends any input events with keyboard or mouse) then, yes, the percentage CPU usage of this only application can be very high.

No, CPU usage of your single application is not defined by its application only. They say, the usage depends on the operating environment. There are other applications. But it's very important that developers develop applications which don't do something stupid, wasting CPU time. And such stupid things are nearly unavoidable if someone develop applications with the goal of having certain percent of CPU usage, no matter low or high.

The OS does its best to balance scheduling using available CPUs or CPU cores and loaded processes, and it's important to used the available resources well, not wasting it and not blocking other processes, and not letting other processes to block yours. And, in fact, this is pretty easy to achieve. It's just enough to avoid some stupid things.

Now, just one practical advise: you can change the priorities of the threads and processes. Don't do it. The cases when it should be done are extremely rare, in all other cases you can only make things worse. First of all, don't do it before you get to good understanding of what applications should do.

—SA
 
Share this answer
 
Comments
Timberbird 26-Dec-14 2:46am    
I can only assume that TS checked Task Manager and discovered his application process uses just one core, 50/25/12.5% of total CPU time. Isn't that ineffective for highly loaded applications?! :)
I agree with you: before you start working with thread priority and processor affinity, you need a good understanding of what you want to achieve and what are the consequences.
Sergey Alexandrovich Kryukov 26-Dec-14 12:43pm    
:-)
Amir Mohammad Nasrollahi 26-Dec-14 4:52am    
Complete answer for this kind of questions and even more :)
Sergey Alexandrovich Kryukov 26-Dec-14 12:42pm    
Thank you, Amir.
—SA
Microsoft has come up with Task Parallel librabrary with .Net framework 4.0
Check out below links.
Multi core programming using Task Parallel Library with .NET 4.0[^]
The Basics of Task Parallelism via C#[^]
 
Share this answer
 
Comments
Praveen Kumar Upadhyay 26-Dec-14 3:22am    
Dear devoter, what OP want is the best thread mechanism which can utilize the cores in equal manner. That is what the overall meaning of this question. So I don't think that I have posted something wrong.

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