Επεξεργασία

Κοινή χρήση μέσω


FileStream.Handle Property

Definition

Caution

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

Caution

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

Caution

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

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

Property Value

IntPtr

nativeint

The operating system file handle for the file encapsulated by this FileStream object, or -1 if the FileStream has been closed.

Attributes

Exceptions

The caller does not have the required permission.

Remarks

This property is an operating system handle for use with operating-system-provided system calls (such as ReadFile on Windows). It will not work with C library functions that expect a file descriptor, such as fread.

The operating system handle might have been opened synchronously or asynchronously, depending on which FileStream constructor was called. Use the IsAsync property to discover whether this handle was opened asynchronously. In Win32, this means the handle was opened for overlapped IO, and it requires different parameters to ReadFile and WriteFile.

Caution

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. Multiple threads cannot safely write to the same file simultaneously, and FileStream buffering code assumes that it exclusively controls the handle. FileStream might throw an IOException if FileStream detects that some other process has moved the file pointer. To 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.

Applies to

See also