FileStream.Handle 属性

定义

注意

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

注意

FileStream.Handle has been deprecated. Use FileStream's SafeFileHandle property instead.

注意

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

获取当前 FileStream 对象所封装文件的操作系统文件句柄。

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; }
[System.Obsolete("FileStream.Handle has been deprecated. Use FileStream's SafeFileHandle property instead.")]
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; }
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 { [System.Security.SecurityCritical] 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
[<System.Obsolete("FileStream.Handle has been deprecated. Use FileStream's SafeFileHandle property instead.")>]
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
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
Public Overridable ReadOnly Property Handle As IntPtr

属性值

IntPtr

nativeint

FileStream 对象所封装文件的操作系统文件句柄;如果 FileStream 已关闭,则为 -1。

属性

例外

调用方没有所要求的权限。

注解

此属性是一个操作系统句柄,用于操作系统提供的系统调用 ((例如 ReadFile 在 Windows) 上)。 它不适用于需要文件描述符的 C 库函数,例如 fread

操作系统句柄可能已同步或异步打开,具体取决于调用的 FileStream 构造函数。 IsAsync使用 属性可发现此句柄是否已异步打开。 在 Win32 中,这意味着已针对重叠 IO 打开句柄,并且需要对 和 WriteFile使用不同的参数ReadFile

注意

如果 FileStream 已创建 ,传递其句柄,某些操作移动句柄的文件指针,然后再次使用 , FileStream 则可能发生数据损坏。 多个线程无法安全地同时写入同一个文件,缓冲 FileStream 代码假定它独占控制句柄。 FileStream如果FileStream检测到其他进程移动了文件指针,可能会引发 IOException 。 若要避免这种情况,请勿将任何数据写入可能已缓冲的文件的 FileStream 某个部分,并将文件指针还原到上次调用 FileStream方法时的方法所在的位置。

适用于

另请参阅