Process.Refresh 方法
放弃有关关联进程的、已缓存到该进程组件内的任何信息。
**命名空间:**System.Diagnostics
**程序集:**System(在 system.dll 中)
语法
声明
Public Sub Refresh
用法
Dim instance As Process
instance.Refresh
public void Refresh ()
public:
void Refresh ()
public void Refresh ()
public function Refresh ()
备注
调用 Refresh 后,对有关每个属性的信息的第一次请求将使该进程组件从关联进程获取新值。
当 Process 组件与进程资源关联时,Process 的属性值将根据关联进程的状态立即填充。如果有关关联进程的信息后来发生更改,则 Process 组件的缓存值中不反映这些更改。Process 组件是它和进程资源关联时后者的快照。若要查看关联进程的当前值,请调用 Refresh 方法。
示例
下面的示例启动一个记事本实例。然后它最多在 10 秒内,以两秒为间隔检索关联进程的物理内存使用情况。该示例检测该进程在经过 10 秒后是否退出。如果该进程在 10 秒后仍在运行,该示例就会将其关闭。
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
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);
}
}
}
}
#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 );
}
}
.NET Framework 安全性
- SecurityPermission 用于调用 Process 的成员。要求值:LinkDemand;命名的权限集:FullTrust。
平台
Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
.NET Compact Framework
受以下版本支持:2.0