C#中的内存使用 [英] Memory usage in C#

查看:20
本文介绍了C#中的内存使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 C# 线程的程序.有没有办法以编程方式了解应用程序的内存使用情况?我想将线程的产生限制为 10 兆字节的内存,我该怎么做?

I have a program that uses threads in C#. Is there a way to know programmatically the memory usage of the application? I want to limit the spawning of threads to say 10 megabytes of memory, how would I do that?

推荐答案

如果你想要整个运行进程的内存而不是每个线程的基础,如何:

If you want the memory of the entire running process and not on a per thread basis, how about:

// get the current process
Process currentProcess = System.Diagnostics.Process.GetCurrentProcess();

// get the physical mem usage
long totalBytesOfMemoryUsed = currentProcess.WorkingSet64;

除了 WorkingSet64 之外,还有许多其他进程内存属性,请在以下链接中查看内存相关"属性,以找到最适合的一个

There's a whole host of other process memory properties besides WorkingSet64 check out the "memory related" ones at the following link for the one that best suit

http://msdn.microsoft.com/en-us/library/system.diagnostics.process_properties.aspx

这篇关于C#中的内存使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆