C#中的内存使用

编程入门 行业动态 更新时间:2024-10-13 16:18:42
本文介绍了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

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

更多推荐

C#中的内存使用

本文发布于:2023-05-29 03:38:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/335879.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:内存

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!