Düzenle

Aracılığıyla paylaş


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
DispatchSource.ReadMonitor
Inheritance
DispatchSource.ReadMonitor

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

DispatchSource.ReadMonitor(Int32, DispatchQueue)

Creates a file descriptor read monitor.

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

Properties

BytesAvailable

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

FileDescriptor

The file descriptor being monitored.

Handle (Inherited from DispatchObject)
IsCanceled

Determine whether the specified source has been canceled.

(Inherited from DispatchSource)

Methods

Activate() (Inherited from DispatchObject)
Cancel()

Asynchronously cancels the dispatch source.

(Inherited from DispatchSource)
Check()
Obsolete.
(Inherited from DispatchObject)
Dispose() (Inherited from DispatchObject)
Dispose(Boolean)

Releases the resources used by the DispatchSource object.

(Inherited from DispatchSource)
Equals(Object) (Inherited from DispatchObject)
GetHashCode()

Returns the hashcode for this object

(Inherited from DispatchObject)
InitializeHandle(IntPtr) (Inherited from NativeObject)
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)

Applies to