GC.WaitForFullGCApproach Méthode

Définition

Retourne l’état d’une notification inscrite pour déterminer si un garbage collection complet et bloquant par le Common Language Runtime est imminent.

Surcharges

Nom Description
WaitForFullGCApproach()

Retourne l’état d’une notification inscrite pour déterminer si un garbage collection complet et bloquant par le Common Language Runtime est imminent.

WaitForFullGCApproach(Int32)

Retourne, dans un délai d’expiration spécifié, l’état d’une notification inscrite pour déterminer si un garbage collection complet bloquant par le Common Language Runtime est imminent.

WaitForFullGCApproach(TimeSpan)

Retourne, dans un délai d’expiration spécifié, l’état d’une notification inscrite pour déterminer si un garbage collection complet bloquant par le Common Language Runtime est imminent.

WaitForFullGCApproach()

Source:
GC.CoreCLR.cs
Source:
GC.CoreCLR.cs
Source:
GC.CoreCLR.cs
Source:
GC.CoreCLR.cs
Source:
GC.CoreCLR.cs

Retourne l’état d’une notification inscrite pour déterminer si un garbage collection complet et bloquant par le Common Language Runtime est imminent.

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

Retours

État de la notification de garbage collection enregistrée.

Attributs

Exemples

L’exemple suivant montre comment utiliser cette méthode pour déterminer si un garbage collection complet bloquant approche. Chaque fois que l’état de la notification est Succeeded, la méthode OnFullGCApproachNotify utilisateur est appelée pour effectuer des actions en réponse à la collecte approche. Cet exemple de code fait partie d’un exemple plus large fourni pour la rubrique Notifications de garbage collection .

// 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

Remarques

Utilisez l’énumération GCNotificationStatus retournée par cette méthode pour déterminer l’état de la notification de garbage collection actuelle inscrite à l’aide de la RegisterForFullGCNotification méthode. Vous pouvez également utiliser la WaitForFullGCComplete méthode pour déterminer si le garbage collection complet est terminé.

Lorsque l’énumération retourne Succeeded, vous pouvez effectuer des tâches telles que la prévention de l’allocation d’objets supplémentaires et l’inducteur d’une collection vous-même avec la Collect méthode. Notez que la notification ne garantit pas qu’un garbage collection complet se produit, seules les conditions ont atteint le seuil favorable pour qu’un garbage collection complet se produise.

Cette méthode attend indéfiniment qu’une notification de garbage collection soit obtenue. Si vous souhaitez spécifier un délai d’attente pour la méthode à retourner si la notification ne peut pas être obtenue, utilisez la GC.WaitForFullGCApproach(Int32) surcharge de méthode. Si vous appelez cette méthode sans spécifier de délai d’attente, vous pouvez appeler la CancelFullGCNotification méthode si vous attendez plus longtemps que par défaut.

Vous devez suivre cette méthode avec un appel à la WaitForFullGCComplete méthode pour vous assurer que vous avez eu un garbage collection complet. L’appel de cette méthode seul entraîne des résultats indéterminés.

Voir aussi

S’applique à

WaitForFullGCApproach(Int32)

Source:
GC.CoreCLR.cs
Source:
GC.CoreCLR.cs
Source:
GC.CoreCLR.cs
Source:
GC.CoreCLR.cs
Source:
GC.CoreCLR.cs

Retourne, dans un délai d’expiration spécifié, l’état d’une notification inscrite pour déterminer si un garbage collection complet bloquant par le Common Language Runtime est imminent.

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

Paramètres

millisecondsTimeout
Int32

Durée d’attente avant qu’un état de notification puisse être obtenu. Spécifiez -1 attendre indéfiniment.

Retours

État de la notification de garbage collection enregistrée.

Attributs

Exceptions

millisecondsTimeout doit être non négatif ou inférieur ou égal à Int32.MaxValue ou -1.

Remarques

Utilisez l’énumération GCNotificationStatus retournée par cette méthode pour déterminer l’état de la notification de garbage collection actuelle inscrite à l’aide de la RegisterForFullGCNotification méthode. Vous pouvez également utiliser la WaitForFullGCComplete méthode pour déterminer si le garbage collection complet est terminé.

Notez que cette méthode retourne immédiatement chaque fois qu’un état de notification de garbage collection est obtenu, quelle que soit la valeur spécifiée par millisecondsTimeout. Si un état de notification de garbage collection n’est pas obtenu avant millisecondsTimeout expiration, cette méthode retourne NotApplicable.

Lorsque l’énumération retourne Succeeded, vous pouvez effectuer des tâches telles que la prévention de l’allocation d’objets supplémentaires et l’inducteur d’une collection vous-même avec la Collect méthode. Notez que la notification ne garantit pas qu’un garbage collection complet se produit, seules les conditions ont atteint le seuil favorable pour qu’un garbage collection complet se produise.

Vous pouvez appeler la CancelFullGCNotification méthode lorsque vous ne pouvez pas attendre que le délai d’attente s’écoule.

Vous devez suivre cette méthode avec un appel à la WaitForFullGCComplete méthode pour vous assurer que vous avez eu un garbage collection complet. L’appel de cette méthode seul entraîne des résultats indéterminés.

Voir aussi

S’applique à

WaitForFullGCApproach(TimeSpan)

Source:
GC.cs
Source:
GC.cs
Source:
GC.cs
Source:
GC.cs
Source:
GC.cs

Retourne, dans un délai d’expiration spécifié, l’état d’une notification inscrite pour déterminer si un garbage collection complet bloquant par le Common Language Runtime est imminent.

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

Paramètres

timeout
TimeSpan

Délai d’attente d’une approche GC complète

Retours

État d’une notification GC complète inscrite

S’applique à