System.IO.InternalBufferOverflowException 类

方法描述

内部缓冲区溢出时引发的异常。

语法定义(C# System.IO.InternalBufferOverflowException 类 的用法)

[SerializableAttribute]
public class InternalBufferOverflowException : SystemException

构造函数

构造函数名称 构造函数描述
InternalBufferOverflowException() 初始化 InternalBufferOverflowException 类的一个新默认实例。
InternalBufferOverflowException(String) 通过指定要显示的错误信息来初始化 InternalBufferOverflowException 类的新实例。
InternalBufferOverflowException(SerializationInfo, StreamingContext) 基础结构。初始化 InternalBufferOverflowException 类的新的空实例,该实例可序列化且使用指定的 SerializationInfo 和 StreamingContext。
InternalBufferOverflowException(String, Exception) 通过指定要显示的消息和生成的内部异常来初始化 InternalBufferOverflowException 类的新实例。

成员/方法

方法名称 方法描述
Equals(Object) 确定指定的 Object 是否等于当前的 Object。 (继承自 Object。)
Finalize 允许对象在“垃圾回收”回收之前尝试释放资源并执行其他清理操作。 (继承自 Object。)
GetBaseException 当在派生类中重写时,返回 Exception,它是一个或多个并发的异常的根源。 (继承自 Exception。)
GetHashCode 用作特定类型的哈希函数。 (继承自 Object。)
GetObjectData 当在派生类中重写时,用关于异常的信息设置 SerializationInfo。 (继承自 Exception。)
GetType 获取当前实例的运行时类型。 (继承自 Exception。)
MemberwiseClone 创建当前 Object 的浅表副本。 (继承自 Object。)
ToString 创建并返回当前异常的字符串表示形式。 (继承自 Exception。)

提示和注释

在 FileSystemWatcher 中,当通知您发生文件更改时,系统将这些更改存储在组件创建并传递给应用程序编程接口 (API) 的缓冲区中。 如果短时间内有很多更改,缓冲区容易发生溢出,这样导致引发异常,而实质上会丢失所有更改。 为防止缓冲区溢出,请使用 FileSystemWatcher.NotifyFilter 和 FileSystemWatcher.IncludeSubdirectories 属性筛选掉不想要的更改通知。 也可以通过 FileSystemWatcher.InternalBufferSize 属性增加内部缓冲区的大小。 但是,增加缓冲区大小的成本较大,所以将缓冲区保持得越小越好。

System.IO.InternalBufferOverflowException 类例子

此示例还演示如何正确接收错误通知。

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));
        }
    }

}

继承层次结构

System.Object

System.Exception

System.SystemException

System.IO.InternalBufferOverflowException

命名空间

namespace: System.IO

程序集: System(在 System.dll 中)

线程安全

此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。

版本信息

.NET Framework 受以下版本支持:4、3.5、3.0、2.0、1.1、1.0 .NET Framework Client Profile 受以下版本支持:4、3.5 SP1

适用平台

Windows 7, Windows Vista SP1 或更高版本, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008(不支持服务器核心), Windows Server 2008 R2(支持 SP1 或更高版本的服务器核心), Windows Server 2003 SP2 .NET Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。