Este artículo se tradujo automáticamente. Para ver el artículo en inglés, active la casilla Inglés. Además, puede mostrar el texto en inglés en una ventana emergente si mueve el puntero del mouse sobre el texto.
Traducción
Inglés

Método Process.Refresh ()

 

Publicado: octubre de 2016

Descarta cualquier información acerca del proceso asociado que se haya almacenado en caché en el componente del proceso.

Espacio de nombres:   System.Diagnostics
Ensamblado:  System (en System.dll)

public void Refresh()

After M:System.Diagnostics.Process.Refresh is called, the first request for information about each property causes the process component to obtain a new value from the associated process.

When a T:System.Diagnostics.Process component is associated with a process resource, the property values of the T:System.Diagnostics.Process are immediately populated according to the status of the associated process. If the information about the associated process subsequently changes, those changes are not reflected in the T:System.Diagnostics.Process component's cached values. The T:System.Diagnostics.Process component is a snapshot of the process resource at the time they are associated. To view the current values for the associated process, call the M:System.Diagnostics.Process.Refresh method.

The following example starts an instance of Notepad. It then retrieves the physical memory usage of the associated process at 2 second intervals for a maximum of 10 seconds. The example detects whether the process exits before 10 seconds have elapsed. The example closes the process if it is still running after 10 seconds.


using System;
using System.Diagnostics;
using System.Threading;

namespace Process_Sample
{
   class MyProcessClass
   {
      public static void 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: " 
                                        + myProcess.WorkingSet.ToString());
                   // 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)
         {
            Console.WriteLine("The following exception was raised: ");
            Console.WriteLine(e.Message);
         }
      }
   }
}

LinkDemand

for full trust for the immediate caller. This member cannot be used by partially trusted code.

.NET Framework
Disponible desde 1.1
Volver al principio
Mostrar: