File.OpenNullHandle Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Opens a handle to the system's null device.
public:
static Microsoft::Win32::SafeHandles::SafeFileHandle ^ OpenNullHandle();
public static Microsoft.Win32.SafeHandles.SafeFileHandle OpenNullHandle();
static member OpenNullHandle : unit -> Microsoft.Win32.SafeHandles.SafeFileHandle
Public Shared Function OpenNullHandle () As SafeFileHandle
Returns
A SafeFileHandle to the system's null device.
Exceptions
An I/O error occurred while opening the null device.
Remarks
On Windows, the method opens a handle to NUL. On Unix-based systems, the method opens a handle to /dev/null.
To redirect unwanted output or provide empty input to processes, use the null device. The null device discards all data written to it and provides no data (EOF) when read from.
The returned handle supports both reading and writing. Read operations return 0 (EOF), and write operations succeed without storing any data. The handle owns the underlying resource, so dispose it when it's no longer needed.
For scenarios that don't require raw file handles or descriptors, consider using Null instead.