Process.Refresh Método

Definición

Descarta cualquier información acerca del proceso asociado que se haya almacenado en caché en el componente del proceso.Discards any information about the associated process that has been cached inside the process component.

public:
 void Refresh();
public void Refresh ();
member this.Refresh : unit -> unit
Public Sub Refresh ()

Ejemplos

En el ejemplo siguiente se inicia una instancia del Bloc de notas.The following example starts an instance of Notepad. A continuación, recupera el uso de memoria física del proceso asociado a intervalos de 2 segundos durante un máximo de 10 segundos.It then retrieves the physical memory usage of the associated process at 2 second intervals for a maximum of 10 seconds. En el ejemplo se detecta si el proceso finaliza antes de que transcurran 10 segundos.The example detects whether the process exits before 10 seconds have elapsed. En el ejemplo se cierra el proceso si aún se está ejecutando después de 10 segundos.The example closes the process if it is still running after 10 seconds.

#using <System.dll>

using namespace System;
using namespace System::Diagnostics;
using namespace System::Threading;
int main()
{
   try
   {
      Process^ myProcess;
      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 : {0}", myProcess->WorkingSet.ToString() );
            
            // Wait 2 seconds.
            Thread::Sleep( 2000 );
         }
         else
         {
            break;
         }

      }
      myProcess->CloseMainWindow();
      
      // Free resources associated with process.
      myProcess->Close();
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "The following exception was raised: " );
      Console::WriteLine( e->Message );
   }

}

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);
            }
        }
    }
}
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

Comentarios

Después de Refresh llamar a, la primera solicitud de información sobre cada propiedad hace que el componente de proceso obtenga un nuevo valor del proceso asociado.After Refresh is called, the first request for information about each property causes the process component to obtain a new value from the associated process.

Cuando un Process componente está asociado a un recurso de proceso, los valores de propiedad de Process se rellenan inmediatamente según el estado del proceso asociado.When a Process component is associated with a process resource, the property values of the Process are immediately populated according to the status of the associated process. Si posteriormente cambia la información sobre el proceso asociado, esos cambios no se reflejan en los Process valores almacenados en caché del componente.If the information about the associated process subsequently changes, those changes are not reflected in the Process component's cached values. El Process componente es una instantánea del recurso de proceso en el momento en que están asociados.The Process component is a snapshot of the process resource at the time they are associated. Para ver los valores actuales del proceso asociado, llame al Refresh método.To view the current values for the associated process, call the Refresh method.

Se aplica a