共用方式為


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方法時所擁有的位置。

適用於

另請參閱