Process.Refresh Metódus
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Elveti a folyamatösszetevőben gyorsítótárazott társított folyamat adatait.
public:
void Refresh();
public void Refresh();
member this.Refresh : unit -> unit
Public Sub Refresh ()
Példák
Az alábbi példa elindítja a Jegyzettömb egy példányát. Ezután lekéri a társított folyamat fizikai memóriahasználatát 2 másodperces időközönként, legfeljebb 10 másodpercig. A példa azt észleli, hogy a folyamat 10 másodperc előtt kilép-e. A példa akkor zárja be a folyamatot, ha 10 másodperc után is fut.
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
Megjegyzések
A meghívás után Refresh az egyes tulajdonságokra vonatkozó első információkérés hatására a folyamatösszetevő új értéket szerez be a társított folyamatból.
Ha egy összetevő egy Process folyamaterőforráshoz van társítva, a rendszer azonnal feltölti az Process összetevők tulajdonságértékeit a társított folyamat állapota alapján. Ha a kapcsolódó folyamat adatai később módosulnak, ezek a módosítások nem jelennek meg az Process összetevő gyorsítótárazott értékeiben. Az Process összetevő a folyamaterőforrás pillanatképe a társításuk időpontjában. A társított folyamat aktuális értékeinek megtekintéséhez hívja meg a metódust Refresh .