FileStream.Handle 属性

定义

注意

This property has been deprecated. Please use FileStream's SafeFileHandle property instead. https://go.microsoft.com/fwlink/?linkid=14202

注意

This property has been deprecated. Please use FileStream's SafeFileHandle property instead. http://go.microsoft.com/fwlink/?linkid=14202

注意

Use SafeFileHandle instead

获取当前 FileStream 对象所封装文件的操作系统文件句柄。Gets the operating system file handle for the file that the current FileStream object encapsulates.

public:
 virtual property IntPtr Handle { IntPtr get(); };
[System.Obsolete("This property has been deprecated.  Please use FileStream's SafeFileHandle property instead.  https://go.microsoft.com/fwlink/?linkid=14202")]
public virtual IntPtr Handle { get; }
public virtual IntPtr Handle { get; }
[System.Obsolete("This property has been deprecated.  Please use FileStream's SafeFileHandle property instead.  http://go.microsoft.com/fwlink/?linkid=14202")]
public virtual IntPtr Handle { get; }
[System.Obsolete("This property has been deprecated.  Please use FileStream's SafeFileHandle property instead.  http://go.microsoft.com/fwlink/?linkid=14202")]
[get: System.Security.SecurityCritical]
public virtual IntPtr Handle { get; }
[System.Obsolete("Use SafeFileHandle instead")]
public virtual IntPtr Handle { get; }
[<System.Obsolete("This property has been deprecated.  Please use FileStream's SafeFileHandle property instead.  https://go.microsoft.com/fwlink/?linkid=14202")>]
member this.Handle : nativeint
member this.Handle : nativeint
[<System.Obsolete("This property has been deprecated.  Please use FileStream's SafeFileHandle property instead.  http://go.microsoft.com/fwlink/?linkid=14202")>]
member this.Handle : nativeint
[<System.Obsolete("This property has been deprecated.  Please use FileStream's SafeFileHandle property instead.  http://go.microsoft.com/fwlink/?linkid=14202")>]
[<get: System.Security.SecurityCritical>]
member this.Handle : nativeint
[<System.Obsolete("Use SafeFileHandle instead")>]
member this.Handle : nativeint
Public Overridable ReadOnly Property Handle As IntPtr

属性值

IntPtr

FileStream 对象所封装文件的操作系统文件句柄;如果 FileStream 已关闭,则为 -1。The operating system file handle for the file encapsulated by this FileStream object, or -1 if the FileStream has been closed.

属性

例外

调用方没有所要求的权限。The caller does not have the required permission.

注解

此属性是用于操作系统提供的系统调用的操作系统句柄, (例如 ReadFile Windows) 上。This property is an operating system handle for use with operating-system-provided system calls (such as ReadFile on Windows). 它不会与需要文件描述符的 C 库函数(如)一起使用 freadIt will not work with C library functions that expect a file descriptor, such as fread.

操作系统句柄可能已同步或异步打开,具体取决于调用的 FileStream 构造函数。The operating system handle might have been opened synchronously or asynchronously, depending on which FileStream constructor was called. 使用 IsAsync 属性来发现此句柄是否已异步打开。Use the IsAsync property to discover whether this handle was opened asynchronously. 在 Win32 中,这意味着打开了重叠 IO 的句柄,它需要和的不同 ReadFile 参数 WriteFileIn Win32, this means the handle was opened for overlapped IO, and it requires different parameters to ReadFile and WriteFile.

注意

如果创建了一个,则会发生数据损坏 FileStream ,而某些操作则会移动句柄的文件指针,然后 FileStream 再次使用。Data corruption might occur if a FileStream is created, its handle is passed, some operation moves the handle's file pointer, and then the FileStream is used again. 多个线程无法同时安全地写入同一文件,并且 FileStream 缓冲代码假定它以独占方式控制句柄。Multiple threads cannot safely write to the same file simultaneously, and FileStream buffering code assumes that it exclusively controls the handle. FileStreamIOException如果 FileStream 检测到其他进程已移动文件指针,则可能会引发。FileStream might throw an IOException if FileStream detects that some other process has moved the file pointer. 若要避免出现这种情况,请不要将任何数据写入可能已进行缓冲处理的文件的一部分 FileStream ,然后将文件指针还原到上一次调用方法时的位置 FileStreamTo avoid this, do not write any data into a portion of the file that FileStream might have buffered, and restore the file pointer to the location it had when methods were last called on FileStream.

适用于