c# - How do i get a specific process name memory usage? -


i tried code:

public static string getprocessmemoryusage(string processname)         {             while (true)             {                 performancecounter performancecounter = new performancecounter();                 performancecounter.categoryname = "process";                 performancecounter.countername = "working set";                 performancecounter.instancename = process.getcurrentprocess().processname;                 processname = ((uint)performancecounter.nextvalue() / 1024).tostring(processname);                 return processname;             }         } 

if process name example: bfbc2game method getprocessmemoryusage return me name: bfbc2game want return me memory usage value number in task manager in windows example when run task manager see on bfbc2game: 78% , 198.5mb memory usage.

thats want in returned string processname: 78% , 198.5mb that. , iwll update time in loop. same in task manager.

use

var workingset = (uint)performancecounter.nextvalue() / 1024; return workingset.tostring(); 

when use uint32.tostring(processname) process name treated format string number. so, have format string "notepad.exe". not have placeholders numbers, result equals format string value, i.e. process name.

note - assigning memory usage value processname variable very confusing. i'd suggest return uint value method:

public static uint getprocessmemoryusageinkilobytes(string processname) {     var performancecounter =          new performancecounter("process", "working set", processname);     return (uint)performancecounter.nextvalue() / 1024; } 

or use process.workingset64 amount of memory allocated process.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -