内存使用C# [英] Memory usage in 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
<一个href="http://msdn.microsoft.com/en-us/library/system.diagnostics.process_properties.aspx">http://msdn.microsoft.com/en-us/library/system.diagnostics.process_properties.aspx
这篇关于内存使用C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!