Bearbeiten

Freigeben über


NSProcessInfo.Notifications.ObservePowerStateDidChange Method

Definition

Overloads

ObservePowerStateDidChange(EventHandler<NSNotificationEventArgs>)

Strongly typed notification for the PowerStateDidChangeNotification constant.

ObservePowerStateDidChange(NSObject, EventHandler<NSNotificationEventArgs>)

Strongly typed notification for the PowerStateDidChangeNotification constant.

ObservePowerStateDidChange(EventHandler<NSNotificationEventArgs>)

Strongly typed notification for the PowerStateDidChangeNotification constant.

public static Foundation.NSObject ObservePowerStateDidChange (EventHandler<Foundation.NSNotificationEventArgs> handler);
static member ObservePowerStateDidChange : EventHandler<Foundation.NSNotificationEventArgs> -> Foundation.NSObject

Parameters

handler
EventHandler<NSNotificationEventArgs>

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 PowerStateDidChangeNotification notifications.

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

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

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

Applies to

ObservePowerStateDidChange(NSObject, EventHandler<NSNotificationEventArgs>)

Strongly typed notification for the PowerStateDidChangeNotification constant.

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

Parameters

objectToObserve
NSObject

The object to observe.

handler
EventHandler<NSNotificationEventArgs>

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 PowerStateDidChangeNotification notifications.

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

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

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

Applies to