Share via


DispatchSource.ReadMonitor Class

Definition

Sources of this type monitor file descriptors for pending data.

public class DispatchSource.ReadMonitor : CoreFoundation.DispatchSource
type DispatchSource.ReadMonitor = class
    inherit DispatchSource
Inheritance

Remarks

The data returned by BytesAvailable is an estimated number of bytes available to be read from the descriptor. This estimate should be treated as a suggested minimum read buffer size.

There are no guarantees that a complete read of this size will be performed.

Users of this source type are strongly encouraged to perform non-blocking I/O and handle any truncated reads or error conditions that may occur.

var stream = File.OpenRead ("Demo.txt");

// The the unix file handle
var safeHandle = stream.SafeFileHandle;
IntPtr descriptor = safeHandle.DangerousGetHandle ();
int fileDescriptor = descriptor.ToInt32 ();

dispatchSource = new DispatchSource.ReadMonitor (fileDescriptor, DispatchQueue.MainQueue);

dispatchSource.SetRegistrationHandler (() => {
    Console.WriteLine ("Read monitor registered");
});

dispatchSource.SetEventHandler (() => {
    Console.WriteLine ("Read monitor: was opened in write mode")
    dispatchSource.Cancel ();
    stream.Close ();
});

dispatchSource.SetCancelHandler (() => {
    Console.WriteLine ("Read monitor cancelled");
});

dispatchSource.Resume ();

Constructors

Name Description
DispatchSource.ReadMonitor(Int32, DispatchQueue)

Creates a file descriptor read monitor.

DispatchSource.ReadMonitor(IntPtr, Boolean)
DispatchSource.ReadMonitor(IntPtr)

Properties

Name Description
BytesAvailable

Estimated number of bytes available to read from the file descriptor.

FileDescriptor

The file descriptor being monitored.

Handle (Inherited from DisposableObject)
IsCanceled

Determine whether the specified source has been canceled.

(Inherited from DispatchSource)
Owns (Inherited from DisposableObject)

Methods

Name Description
Activate() (Inherited from DispatchObject)
Cancel()

Asynchronously cancels the dispatch source.

(Inherited from DispatchSource)
ClearHandle() (Inherited from DisposableObject)
Dispose() (Inherited from DisposableObject)
Dispose(Boolean)

Releases the resources used by the DispatchSource object.

(Inherited from DispatchSource)
Equals(Object) (Inherited from DisposableObject)
GetCheckedHandle() (Inherited from DisposableObject)
GetHashCode() (Inherited from DisposableObject)
InitializeHandle(NativeHandle) (Inherited from DisposableObject)
Release() (Inherited from DispatchObject)
Resume()

Resumes the dispatch source.

(Inherited from DispatchSource)
Retain() (Inherited from DispatchObject)
SetCancelHandler(Action)

Provides a cancellation handler

(Inherited from DispatchSource)
SetEventHandler(Action)

Specified a handler to execute when events are received on the dispatch source.

(Inherited from DispatchSource)
SetRegistrationHandler(Action)

Provides a registration handler

(Inherited from DispatchSource)
SetTargetQueue(DispatchQueue) (Inherited from DispatchObject)
Suspend()

Suspends the dispatch source.

(Inherited from DispatchSource)

Extension Methods

Name Description
GetHandle(INativeObject)
GetNonNullHandle(INativeObject, String)

Applies to