[英]there is a way to check how much ram is being used by a specific windows service?
我需要知道當時 Windows 服務或程序使用了多少內存,但我不知道如何到達那里。
這讓我重新啟動我在服務控制器上指示的服務,但只有當 ram 超過我必須指示的某個值時,我才必須這樣做
ServiceController service = new ServiceController("MSSQLSERVER");
try
{
int millisec1 = Environment.TickCount;
TimeSpan timeout = TimeSpan.FromMilliseconds(100000);
service.Stop();
service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
int millisec2 = Environment.TickCount;
timeout = TimeSpan.FromMilliseconds(50000 - (millisec2 - millisec1));
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running, timeout);
}
catch
{
Console.WriteLine("Errore");
Console.ReadLine();
}
如果您只知道進程名稱,則可以執行
var process = Process.GetProcessesByName("explorer").FirstOrDefault();
var memoryUsed = process?.PrivateMemorySize64;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.