Process.Refresh 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
프로세스 구성 요소 내에 캐시된 연결된 프로세스에 대한 모든 정보를 삭제합니다.
public:
void Refresh();
public void Refresh();
member this.Refresh : unit -> unit
Public Sub Refresh ()
예제
다음 예제에서는 메모장 인스턴스를 시작합니다. 그런 다음, 최대 10초 동안 2초 간격으로 연결된 프로세스의 실제 메모리 사용량을 검색합니다. 이 예제에서는 10초가 경과하기 전에 프로세스가 종료되는지 여부를 검색합니다. 이 예제에서는 10초 후에도 계속 실행 중인 경우 프로세스를 닫습니다.
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Threading;
namespace ProcessSample
{
class MyProcessClass
{
public static void Main()
{
try
{
using (Process myProcess = Process.Start("Notepad.exe"))
{
// Display physical memory usage 5 times at intervals of 2 seconds.
for (int i = 0; i < 5; i++)
{
if (!myProcess.HasExited)
{
// Discard cached information about the process.
myProcess.Refresh();
// Print working set to console.
Console.WriteLine($"Physical Memory Usage: {myProcess.WorkingSet}");
// Wait 2 seconds.
Thread.Sleep(2000);
}
else
{
break;
}
}
// Close process by sending a close message to its main window.
myProcess.CloseMainWindow();
// Free resources associated with process.
myProcess.Close();
}
}
catch (Exception e) when (e is Win32Exception || e is FileNotFoundException)
{
Console.WriteLine("The following exception was raised: ");
Console.WriteLine(e.Message);
}
}
}
}
open System.ComponentModel
open System.Diagnostics
open System.IO
open System.Threading
try
use myProcess = Process.Start "Notepad.exe"
// Display physical memory usage 5 times at intervals of 2 seconds.
let mutable i = 0
while i < 5 && not myProcess.HasExited do
// Discard cached information about the process.
myProcess.Refresh()
// Print working set to console.
printfn $"Physical Memory Usage: {myProcess.WorkingSet64}"
// Wait 2 seconds.
Thread.Sleep 2000
i <- i + 1
// Close process by sending a close message to its main window.
myProcess.CloseMainWindow() |> ignore
// Free resources associated with process.
myProcess.Close()
with
| :? Win32Exception
| :? FileNotFoundException as e ->
printfn "The following exception was raised: "
printfn $"{e.Message}"
Imports System.ComponentModel
Imports System.Diagnostics
Imports System.IO
Imports System.Threading
Namespace Process_Sample
Class MyProcessClass
Public Shared Sub Main()
Try
Using myProcess = Process.Start("Notepad.exe")
' Display physical memory usage 5 times at intervals of 2 seconds.
Dim i As Integer
For i = 0 To 4
If Not myProcess.HasExited Then
' Discard cached information about the process.
myProcess.Refresh()
' Print working set to console.
Console.WriteLine($"Physical Memory Usage: {myProcess.WorkingSet}")
' Wait 2 seconds.
Thread.Sleep(2000)
Else
Exit For
End If
Next i
' Close process by sending a close message to its main window.
myProcess.CloseMainWindow()
' Free resources associated with process.
myProcess.Close()
End Using
Catch e As Exception When TypeOf e Is Win32Exception Or TypeOf e Is FileNotFoundException
Console.WriteLine("The following exception was raised: ")
Console.WriteLine(e.Message)
End Try
End Sub
End Class
End Namespace 'Process_Sample
설명
호출된 후 Refresh 각 속성에 대한 정보에 대한 첫 번째 요청은 프로세스 구성 요소가 연결된 프로세스에서 새 값을 얻도록 합니다.
Process 구성 요소가 프로세스 리소스와 연결되면 연결된 프로세스의 Process 상태에 따라 해당 속성 값이 즉시 채워집니다. 관련 프로세스에 대한 정보가 이후에 변경되면 해당 변경 내용은 구성 요소의 캐시된 값에 Process 반영되지 않습니다. Process 구성 요소는 연결된 프로세스 리소스의 스냅샷입니다. 연결된 프로세스의 현재 값을 보려면 메서드를 호출합니다 Refresh .