InternalBufferOverflowException Classe
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Exception levée lorsque la mémoire tampon interne dépasse.
public ref class InternalBufferOverflowException : SystemException
public class InternalBufferOverflowException : SystemException
[System.Serializable]
public class InternalBufferOverflowException : SystemException
type InternalBufferOverflowException = class
inherit SystemException
[<System.Serializable>]
type InternalBufferOverflowException = class
inherit SystemException
Public Class InternalBufferOverflowException
Inherits SystemException
- Héritage
- Attributs
Exemples
L’exemple suivant montre comment créer un FileSystemWatcher pour surveiller les modifications de fichier (crée, supprime, renomme, modifications) sur un lecteur de disque. L’exemple montre également comment recevoir correctement des notifications d’erreur.
using System;
using System.IO;
class Program
{
static void Main(string[] args)
{
// Create a FileSystemWatcher to monitor all files on drive C.
FileSystemWatcher fsw = new FileSystemWatcher("C:\\");
// Watch for changes in LastAccess and LastWrite times, and
// the renaming of files or directories.
fsw.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName |NotifyFilters.DirectoryName;
// Register a handler that gets called when a
// file is created, changed, or deleted.
fsw.Changed += new FileSystemEventHandler(OnChanged);
fsw.Created += new FileSystemEventHandler(OnChanged);
fsw.Deleted += new FileSystemEventHandler(OnChanged);
// Register a handler that gets called when a file is renamed.
fsw.Renamed += new RenamedEventHandler(OnRenamed);
// Register a handler that gets called if the
// FileSystemWatcher needs to report an error.
fsw.Error += new ErrorEventHandler(OnError);
// Begin watching.
fsw.EnableRaisingEvents = true;
Console.WriteLine("Press \'Enter\' to quit the sample.");
Console.ReadLine();
}
// This method is called when a file is created, changed, or deleted.
private static void OnChanged(object source, FileSystemEventArgs e)
{
// Show that a file has been created, changed, or deleted.
WatcherChangeTypes wct = e.ChangeType;
Console.WriteLine("File {0} {1}", e.FullPath, wct.ToString());
}
// This method is called when a file is renamed.
private static void OnRenamed(object source, RenamedEventArgs e)
{
// Show that a file has been renamed.
WatcherChangeTypes wct = e.ChangeType;
Console.WriteLine("File {0} {2} to {1}", e.OldFullPath, e.FullPath, wct.ToString());
}
// This method is called when the FileSystemWatcher detects an error.
private static void OnError(object source, ErrorEventArgs e)
{
// Show that an error has been detected.
Console.WriteLine("The FileSystemWatcher has detected an error");
// Give more information if the error is due to an internal buffer overflow.
if (e.GetException().GetType() == typeof(InternalBufferOverflowException))
{
// This can happen if Windows is reporting many file system events quickly
// and internal buffer of the FileSystemWatcher is not large enough to handle this
// rate of events. The InternalBufferOverflowException error informs the application
// that some of the file system events are being lost.
Console.WriteLine(("The file system watcher experienced an internal buffer overflow: " + e.GetException().Message));
}
}
}
Imports System.IO
Module Module1
Sub Main()
' Create a FileSystemWatcher to monitor all files on drive C.
Dim fsw As New FileSystemWatcher("C:\")
' Watch for changes in LastAccess and LastWrite times, and
' the renaming of files or directories.
fsw.NotifyFilter = (NotifyFilters.LastAccess Or NotifyFilters.LastWrite _
Or NotifyFilters.FileName Or NotifyFilters.DirectoryName)
' Register a handler that gets called when a
' file is created, changed, or deleted.
AddHandler fsw.Changed, New FileSystemEventHandler(AddressOf OnChanged)
' The commented line of code below is a shorthand of the above line.
' AddHandler fsw.Changed, AddressOf OnChanged
' NOTE: The shorthand version is used in the remainder of this code.
' FileSystemEventHandler
AddHandler fsw.Created, AddressOf OnChanged
' FileSystemEventHandler
AddHandler fsw.Deleted, AddressOf OnChanged
' Register a handler that gets called when a file is renamed.
' RenamedEventHandler
AddHandler fsw.Renamed, AddressOf OnRenamed
' Register a handler that gets called if the
' FileSystemWatcher needs to report an error.
' ErrorEventHandler
AddHandler fsw.Error, AddressOf OnError
' Begin watching.
fsw.EnableRaisingEvents = True
' Wait for the user to quit the program.
Console.WriteLine("Press 'Enter' to quit the sample.")
Console.ReadLine()
End Sub
' This method is called when a file is created, changed, or deleted.
Private Sub OnChanged(ByVal source As Object, ByVal e As FileSystemEventArgs)
' Show that a file has been created, changed, or deleted.
Dim wct As WatcherChangeTypes = e.ChangeType
Console.WriteLine("File {0} {1}", e.FullPath, wct.ToString())
End Sub
' This method is called when a file is renamed.
Private Sub OnRenamed(ByVal source As Object, ByVal e As RenamedEventArgs)
' Show that a file has been renamed.
Dim wct As WatcherChangeTypes = e.ChangeType
Console.WriteLine("File {0} {2} to {1}", e.OldFullPath, e.FullPath, wct.ToString())
End Sub
' This method is called when the FileSystemWatcher detects an error.
Private Sub OnError(ByVal source As Object, ByVal e As ErrorEventArgs)
' Show that an error has been detected.
Console.WriteLine("The FileSystemWatcher has detected an error")
' Give more information if the error is due to an internal buffer overflow.
If TypeOf e.GetException Is InternalBufferOverflowException Then
' This can happen if Windows is reporting many file system events quickly
' and internal buffer of the FileSystemWatcher is not large enough to handle this
' rate of events. The InternalBufferOverflowException error informs the application
' that some of the file system events are being lost.
Console.WriteLine( _
"The file system watcher experienced an internal buffer overflow: " _
+ e.GetException.Message)
End If
End Sub
End Module
Remarques
Dans un FileSystemWatcher, lorsque vous êtes averti des modifications de fichier, le système stocke ces modifications dans une mémoire tampon que le composant crée et passe aux API (Application Programming Interfaces). S’il existe de nombreuses modifications dans un court délai, la mémoire tampon peut facilement dépasser, ce qui entraîne la levée d’une exception, ce qui perd essentiellement toutes les modifications. Pour empêcher le dépassement de capacité de la mémoire tampon, utilisez les propriétés et FileSystemWatcher.IncludeSubdirectories les FileSystemWatcher.NotifyFilter propriétés pour filtrer vos notifications de modification indésirables. Vous pouvez également augmenter la taille de la mémoire tampon interne par le biais de la FileSystemWatcher.InternalBufferSize propriété. Toutefois, l’augmentation de la taille de la mémoire tampon est coûteuse, de sorte que la mémoire tampon reste aussi petite que possible.
Constructeurs
| Nom | Description |
|---|---|
| InternalBufferOverflowException() |
Initialise une nouvelle instance par défaut de la InternalBufferOverflowException classe. |
| InternalBufferOverflowException(SerializationInfo, StreamingContext) |
Obsolète.
Initialise une nouvelle instance vide de la classe sérialisable à l’aide InternalBufferOverflowException des objets et StreamingContext des objets spécifiésSerializationInfo. |
| InternalBufferOverflowException(String, Exception) |
Initialise une nouvelle instance de la InternalBufferOverflowException classe avec le message à afficher et l’exception interne générée spécifiée. |
| InternalBufferOverflowException(String) |
Initialise une nouvelle instance de la InternalBufferOverflowException classe avec le message d’erreur à afficher. |
Propriétés
| Nom | Description |
|---|---|
| Data |
Obtient une collection de paires clé/valeur qui fournissent des informations supplémentaires définies par l’utilisateur sur l’exception. (Hérité de Exception) |
| HelpLink |
Obtient ou définit un lien vers le fichier d’aide associé à cette exception. (Hérité de Exception) |
| HResult |
Obtient ou définit HRESULT, valeur numérique codée affectée à une exception spécifique. (Hérité de Exception) |
| InnerException |
Obtient l’instance Exception qui a provoqué l’exception actuelle. (Hérité de Exception) |
| Message |
Obtient un message qui décrit l’exception actuelle. (Hérité de Exception) |
| Source |
Obtient ou définit le nom de l’application ou de l’objet qui provoque l’erreur. (Hérité de Exception) |
| StackTrace |
Obtient une représentation sous forme de chaîne des images immédiates sur la pile des appels. (Hérité de Exception) |
| TargetSite |
Obtient la méthode qui lève l’exception actuelle. (Hérité de Exception) |
Méthodes
| Nom | Description |
|---|---|
| Equals(Object) |
Détermine si l’objet spécifié est égal à l’objet actuel. (Hérité de Object) |
| GetBaseException() |
En cas de substitution dans une classe dérivée, retourne la Exception cause racine d’une ou plusieurs exceptions ultérieures. (Hérité de Exception) |
| GetHashCode() |
Sert de fonction de hachage par défaut. (Hérité de Object) |
| GetObjectData(SerializationInfo, StreamingContext) |
Obsolète.
En cas de substitution dans une classe dérivée, définit les SerializationInfo informations relatives à l’exception. (Hérité de Exception) |
| GetType() |
Obtient le type d’exécution de l’instance actuelle. (Hérité de Exception) |
| MemberwiseClone() |
Crée une copie superficielle du Objectactuel. (Hérité de Object) |
| ToString() |
Crée et retourne une représentation sous forme de chaîne de l’exception actuelle. (Hérité de Exception) |
Événements
| Nom | Description |
|---|---|
| SerializeObjectState |
Obsolète.
Se produit lorsqu’une exception est sérialisée pour créer un objet d’état d’exception qui contient des données sérialisées sur l’exception. (Hérité de Exception) |