How would you do this in c#, an example in c++ is:
void PrintMemoryInfo( DWORD processID )
{
std::ofstream fs("d:\processInfo.txt");
fs<<"Information of Process:
";
HANDLE hProcess;
PROCESS_MEMORY_COUNTERS pmc;
fs<<"
Process ID: %u
"<<processID;
hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );
if (NULL == hProcess) return;
if ( GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc)) ) {
fs<< " PageFaultCount: 0x%08X
" << pmc.PageFaultCount;
fs<< " Your app's PEAK MEMORY CONSUMPTION: 0x%08X
"<<pmc.PeakWorkingSetSize;
fs<< " Your app's CURRENT MEMORY CONSUMPTION: 0x%08X
"<< pmc.WorkingSetSize;
fs<< " QuotaPeakPagedPoolUsage: 0x%08X
"<<
pmc.QuotaPeakPagedPoolUsage;
fs<< " QuotaPagedPoolUsage: 0x%08X
"<<
pmc.QuotaPagedPoolUsage;
fs<< " QuotaPeakNonPagedPoolUsage: 0x%08X
"<<
pmc.QuotaPeakNonPagedPoolUsage;
fs<< " QuotaNonPagedPoolUsage: 0x%08X
"<<
pmc.QuotaNonPagedPoolUsage;
fs<< " PagefileUsage: 0x%08X
"<< pmc.PagefileUsage;
fs<< " PeakPagefileUsage: 0x%08X
"<<
pmc.PeakPagefileUsage;
}
fs.close();
CloseHandle( hProcess);
}
int main( )
{
PrintMemoryInfo( GetCurrentProcessId() );
return 0;
}
but in c#?...
See Question&Answers more detail:os