Düzenle

Aracılığıyla paylaş


NSFileHandle.Notifications.ObserveReadCompletion Method

Definition

Overloads

ObserveReadCompletion(EventHandler<NSFileHandleReadEventArgs>)

Strongly typed notification for the ReadCompletionNotification constant.

ObserveReadCompletion(NSObject, EventHandler<NSFileHandleReadEventArgs>)

Strongly typed notification for the ReadCompletionNotification constant.

ObserveReadCompletion(EventHandler<NSFileHandleReadEventArgs>)

Strongly typed notification for the ReadCompletionNotification constant.

public static Foundation.NSObject ObserveReadCompletion (EventHandler<Foundation.NSFileHandleReadEventArgs> handler);
static member ObserveReadCompletion : EventHandler<Foundation.NSFileHandleReadEventArgs> -> Foundation.NSObject

Parameters

handler
EventHandler<NSFileHandleReadEventArgs>

Method to invoke when the notification is posted.

Returns

Token object that can be used to stop receiving notifications by either disposing it or passing it to RemoveObservers(IEnumerable<NSObject>)

Remarks

The following example shows how developers can use this method in their code:

//
// Lambda style
//

// listening
notification = NSFileHandle.Notifications.ObserveReadCompletion ((sender, args) => {
    /* Access strongly typed args */
    Console.WriteLine ("Notification: {0}", args.Notification);

    Console.WriteLine ("AvailableData", args.AvailableData);
    Console.WriteLine ("UnixErrorCode", args.UnixErrorCode);
});

// To stop listening:
notification.Dispose ();

//
//Method style
//
NSObject notification;
void Callback (object sender, Foundation.NSFileHandleReadEventArgs args)
{
    // Access strongly typed args
    Console.WriteLine ("Notification: {0}", args.Notification);

    Console.WriteLine ("AvailableData", args.AvailableData);
    Console.WriteLine ("UnixErrorCode", args.UnixErrorCode);
}

void Setup ()
{
    notification = NSFileHandle.Notifications.ObserveReadCompletion (Callback);
}

void Teardown ()
{
    notification.Dispose ();
}

Applies to

ObserveReadCompletion(NSObject, EventHandler<NSFileHandleReadEventArgs>)

Strongly typed notification for the ReadCompletionNotification constant.

public static Foundation.NSObject ObserveReadCompletion (Foundation.NSObject objectToObserve, EventHandler<Foundation.NSFileHandleReadEventArgs> handler);
static member ObserveReadCompletion : Foundation.NSObject * EventHandler<Foundation.NSFileHandleReadEventArgs> -> Foundation.NSObject

Parameters

objectToObserve
NSObject

The object to observe.

handler
EventHandler<NSFileHandleReadEventArgs>

Method to invoke when the notification is posted.

Returns

Token object that can be used to stop receiving notifications by either disposing it or passing it to RemoveObservers(IEnumerable<NSObject>)

Remarks

This method can be used to subscribe for ReadCompletionNotification notifications.

// Listen to all notifications posted for any object
var token = NSFileHandle.Notifications.ObserveReadCompletion ((notification) => {
	Console.WriteLine ("Observed ReadCompletionNotification!");
};

// Listen to all notifications posted for a single object
var token = NSFileHandle.Notifications.ObserveReadCompletion (objectToObserve, (notification) => {
	Console.WriteLine ($"Observed ReadCompletionNotification for {nameof (objectToObserve)}!");
};

// Stop listening for notifications
token.Dispose ();

Applies to