Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Gibt alle dieser Komponente zugeordneten Ressourcen frei.
Namespace: System.Diagnostics
Assembly: System (in system.dll)
Syntax
'Declaration
Public Sub Close
'Usage
Dim instance As Process
instance.Close
public void Close ()
public:
void Close ()
public void Close ()
public function Close ()
Beispiel
Im folgenden Beispiel wird eine Instanz von Editor gestartet. Anschließend wird die Auslastung des physikalischen Speichers durch den zugeordneten Prozess in Intervallen von zwei Sekunden für maximal zehn Sekunden abgerufen. Dabei wird ermittelt, ob der Prozess vor Ablauf von zehn Sekunden beendet wird. Im Beispiel wird der Prozess beendet, wenn er nach zehn Sekunden weiterhin ausgeführt wird.
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-Sicherheit
- SecurityPermission zum Aufrufen von Process-Membern. Anforderungswert: LinkDemand; Benannte Berechtigungssätze: FullTrust.
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
.NET Compact Framework
Unterstützt in: 2.0