Process.Refresh Method
Discards any information about the associated process that has been cached inside the process component.
[Visual Basic] Public Sub Refresh() [C#] public void Refresh(); [C++] public: void Refresh(); [JScript] public function Refresh();
Remarks
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.
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. If the information about the associated process subsequently changes, those changes are not reflected in the Process component's cached values. The 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 Refresh method.
Example
[Visual Basic, C#, C++] 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.
[Visual Basic] Imports System Imports System.Diagnostics Imports System.Threading Namespace Process_Sample Class MyProcessClass Public Shared Sub Main() Try Dim myProcess As Process 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.ToString()) ' 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() Catch e As Exception Console.WriteLine("The following exception was raised: ") Console.WriteLine(e.Message) End Try End Sub 'Main End Class 'MyProcessClass End Namespace 'Process_Sample [C#] 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); } } } } [C++] #using <mscorlib.dll> #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(S"Physical Memory Usage : {0}", 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(S"The following exception was raised: "); Console::WriteLine(e->Message); } }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
.NET Framework Security:
- SecurityPermission for calling any members of System.Diagnostic.Process with full trust. Associated enumeration: PermissionState.Unrestricted
See Also
Process Class | Process Members | System.Diagnostics Namespace