GC.WaitForFullGCApproach Methode

Definition

Gibt den Status einer registrierten Benachrichtigung zurück, um zu bestimmen, ob eine vollständige blockierende Garbage Collection durch die Common Language Runtime bevorsteht.

Überlädt

WaitForFullGCApproach()

Gibt den Status einer registrierten Benachrichtigung zurück, um zu bestimmen, ob eine vollständige blockierende Garbage Collection durch die Common Language Runtime bevorsteht.

WaitForFullGCApproach(Int32)

Gibt innerhalb einer angegebenen Timeoutspanne den Status einer registrierten Benachrichtigung zurück, um zu bestimmen, ob eine vollständige blockierende Garbage Collection durch die Common Language Runtime bevorsteht.

WaitForFullGCApproach(TimeSpan)

Gibt innerhalb einer angegebenen Timeoutspanne den Status einer registrierten Benachrichtigung zurück, um zu bestimmen, ob eine vollständige blockierende Garbage Collection durch die Common Language Runtime bevorsteht.

WaitForFullGCApproach()

Gibt den Status einer registrierten Benachrichtigung zurück, um zu bestimmen, ob eine vollständige blockierende Garbage Collection durch die Common Language Runtime bevorsteht.

public:
 static GCNotificationStatus WaitForFullGCApproach();
public static GCNotificationStatus WaitForFullGCApproach ();
[System.Security.SecurityCritical]
public static GCNotificationStatus WaitForFullGCApproach ();
static member WaitForFullGCApproach : unit -> GCNotificationStatus
[<System.Security.SecurityCritical>]
static member WaitForFullGCApproach : unit -> GCNotificationStatus
Public Shared Function WaitForFullGCApproach () As GCNotificationStatus

Gibt zurück

Der Status der registrierten Garbage Collection-Benachrichtigung.

Attribute

Beispiele

Das folgende Beispiel zeigt, wie Sie mit dieser Methode ermitteln, ob eine vollständige, blockierende Garbage Collection näher kommt. Immer wenn der status der Benachrichtigung istSucceeded, wird die Benutzermethode OnFullGCApproachNotify aufgerufen, um Aktionen als Reaktion auf die sich nähernde Auflistung auszuführen. Dieses Codebeispiel ist Teil eines größeren Beispiels, das für das Thema Garbage Collection Notifications bereitgestellt wird.

// Check for a notification of an approaching collection.
GCNotificationStatus s = GC::WaitForFullGCApproach();
if (s == GCNotificationStatus::Succeeded)
{
    Console::WriteLine("GC Notifiction raised.");
    OnFullGCApproachNotify();
}
else if (s == GCNotificationStatus::Canceled)
{
    Console::WriteLine("GC Notification cancelled.");
    break;
}
else
{
    // This can occur if a timeout period
    // is specified for WaitForFullGCApproach(Timeout)
    // or WaitForFullGCComplete(Timeout)
    // and the time out period has elapsed.
    Console::WriteLine("GC Notification not applicable.");
    break;
}
// Check for a notification of an approaching collection.
GCNotificationStatus s = GC.WaitForFullGCApproach();
if (s == GCNotificationStatus.Succeeded)
{
    Console.WriteLine("GC Notification raised.");
    OnFullGCApproachNotify();
}
else if (s == GCNotificationStatus.Canceled)
{
    Console.WriteLine("GC Notification cancelled.");
    break;
}
else
{
    // This can occur if a timeout period
    // is specified for WaitForFullGCApproach(Timeout)
    // or WaitForFullGCComplete(Timeout)
    // and the time out period has elapsed.
    Console.WriteLine("GC Notification not applicable.");
    break;
}
// Check for a notification of an approaching collection.
match GC.WaitForFullGCApproach() with
| GCNotificationStatus.Succeeded ->
    printfn "GC Notification raised."
    onFullGCApproachNotify ()
    // Check for a notification of a completed collection.
    match GC.WaitForFullGCComplete() with
    | GCNotificationStatus.Succeeded ->
        printfn "GC Notification raised."
        onFullGCCompleteEndNotify ()
    | GCNotificationStatus.Canceled ->
        printfn "GC Notification cancelled."
        broken <- true
    | _ ->
        // Could be a time out.
        printfn "GC Notification not applicable."
        broken <- true
| GCNotificationStatus.Canceled ->
    printfn "GC Notification cancelled."
    broken <- true
| _ ->
    // This can occur if a timeout period
    // is specified for WaitForFullGCApproach(Timeout)
    // or WaitForFullGCComplete(Timeout)
    // and the time out period has elapsed.
    printfn "GC Notification not applicable."
    broken <- true
' Check for a notification of an approaching collection.
Dim s As GCNotificationStatus = GC.WaitForFullGCApproach
If (s = GCNotificationStatus.Succeeded) Then
    Console.WriteLine("GC Notification raised.")
    OnFullGCApproachNotify()
ElseIf (s = GCNotificationStatus.Canceled) Then
    Console.WriteLine("GC Notification cancelled.")
    Exit While
Else
    ' This can occur if a timeout period
    ' is specified for WaitForFullGCApproach(Timeout) 
    ' or WaitForFullGCComplete(Timeout)  
    ' and the time out period has elapsed. 
    Console.WriteLine("GC Notification not applicable.")
    Exit While
End If

Hinweise

Verwenden Sie die GCNotificationStatus von dieser Methode zurückgegebene Enumeration, um die status der aktuellen Garbage Collection-Benachrichtigung zu ermitteln, die mit der RegisterForFullGCNotification -Methode registriert wurde. Sie können auch die WaitForFullGCComplete -Methode verwenden, um zu bestimmen, ob die vollständige Garbage Collection abgeschlossen wurde.

Wenn die Enumeration zurückgibt Succeeded, können Sie Aufgaben ausführen, z. B. verhindern, dass zusätzliche Objekte zugewiesen werden, und eine Auflistung selbst mit der Collect -Methode induzieren. Beachten Sie, dass die Benachrichtigung nicht garantiert, dass eine vollständige Garbage Collection erfolgt, nur dass bedingungen den Schwellenwert erreicht haben, der für eine vollständige Garbage Collection vorteilhaft ist.

Diese Methode wartet unbegrenzt, bis eine Garbage Collection-Benachrichtigung abgerufen wird. Wenn Sie einen Timeoutzeitraum für die Methode angeben möchten, die zurückgegeben werden soll, wenn die Benachrichtigung nicht abgerufen werden kann, verwenden Sie die GC.WaitForFullGCApproach(Int32) Methodenüberladung. Wenn Sie diese Methode aufrufen, ohne ein Timeout anzugeben, können Sie die CancelFullGCNotification -Methode aufrufen, wenn Sie länger als bevorzugt warten.

Sie sollten diese Methode mit einem Aufruf der WaitForFullGCComplete -Methode befolgen, um sicherzustellen, dass Sie über eine vollständige Garbage Collection verfügen. Allein der Aufruf dieser Methode führt zu unbestimmten Ergebnissen.

Weitere Informationen

Gilt für:

WaitForFullGCApproach(Int32)

Gibt innerhalb einer angegebenen Timeoutspanne den Status einer registrierten Benachrichtigung zurück, um zu bestimmen, ob eine vollständige blockierende Garbage Collection durch die Common Language Runtime bevorsteht.

public:
 static GCNotificationStatus WaitForFullGCApproach(int millisecondsTimeout);
public static GCNotificationStatus WaitForFullGCApproach (int millisecondsTimeout);
[System.Security.SecurityCritical]
public static GCNotificationStatus WaitForFullGCApproach (int millisecondsTimeout);
static member WaitForFullGCApproach : int -> GCNotificationStatus
[<System.Security.SecurityCritical>]
static member WaitForFullGCApproach : int -> GCNotificationStatus
Public Shared Function WaitForFullGCApproach (millisecondsTimeout As Integer) As GCNotificationStatus

Parameter

millisecondsTimeout
Int32

Die Dauer der Wartezeit, bevor ein Benachrichtigungsstatus abgerufen werden kann. Geben Sie -1 an, um unbegrenzt zu warten.

Gibt zurück

Der Status der registrierten Garbage Collection-Benachrichtigung.

Attribute

Ausnahmen

millisecondsTimeout muss entweder nicht negativ oder kleiner oder gleich Int32.MaxValue oder -1 sein.

Hinweise

Verwenden Sie die GCNotificationStatus von dieser Methode zurückgegebene Enumeration, um die status der aktuellen Garbage Collection-Benachrichtigung zu ermitteln, die mit der RegisterForFullGCNotification -Methode registriert wurde. Sie können auch die WaitForFullGCComplete -Methode verwenden, um zu bestimmen, ob die vollständige Garbage Collection abgeschlossen wurde.

Beachten Sie, dass diese Methode sofort zurückgibt, wenn eine Garbage Collection-Benachrichtigung status abgerufen wird, unabhängig vom durch millisecondsTimeoutangegebenen Wert. Wenn eine Garbage Collection-Benachrichtigung status nicht abgerufen wird, bevor ein millisecondsTimeout Zeitüberschreitung aufgetreten ist, gibt diese Methode zurückNotApplicable.

Wenn die Enumeration zurückgibt Succeeded, können Sie Aufgaben ausführen, z. B. verhindern, dass zusätzliche Objekte zugewiesen werden, und eine Auflistung selbst mit der Collect -Methode induzieren. Beachten Sie, dass die Benachrichtigung nicht garantiert, dass eine vollständige Garbage Collection erfolgt, nur dass bedingungen den Schwellenwert erreicht haben, der für eine vollständige Garbage Collection vorteilhaft ist.

Sie können die CancelFullGCNotification -Methode aufrufen, wenn Sie nicht warten können, bis der Timeoutzeitraum abgelaufen ist.

Sie sollten diese Methode mit einem Aufruf der WaitForFullGCComplete -Methode befolgen, um sicherzustellen, dass Sie über eine vollständige Garbage Collection verfügen. Allein der Aufruf dieser Methode führt zu unbestimmten Ergebnissen.

Weitere Informationen

Gilt für:

WaitForFullGCApproach(TimeSpan)

Gibt innerhalb einer angegebenen Timeoutspanne den Status einer registrierten Benachrichtigung zurück, um zu bestimmen, ob eine vollständige blockierende Garbage Collection durch die Common Language Runtime bevorsteht.

public:
 static GCNotificationStatus WaitForFullGCApproach(TimeSpan timeout);
public static GCNotificationStatus WaitForFullGCApproach (TimeSpan timeout);
static member WaitForFullGCApproach : TimeSpan -> GCNotificationStatus
Public Shared Function WaitForFullGCApproach (timeout As TimeSpan) As GCNotificationStatus

Parameter

timeout
TimeSpan

Das Timeout beim Warten auf einen vollständigen GC-Ansatz

Gibt zurück

Die status einer registrierten vollständigen GC-Benachrichtigung

Gilt für: