PackageCatalog.OpenForPackage(Package) Method

Definition

Allows listening to any Package and its dependents (optional, resource, and hostRuntime).

public:
 static PackageCatalog ^ OpenForPackage(Package ^ package);
 static PackageCatalog OpenForPackage(Package const& package);
public static PackageCatalog OpenForPackage(Package package);
function openForPackage(package)
Public Shared Function OpenForPackage (package As Package) As PackageCatalog

Parameters

package
Package

The Package which will be monitored for notifications.

Returns

The PackageCatalog used to listen for deployment notifications.

Windows requirements

Device family
Windows 11 Insider Preview (introduced in 10.0.23504.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v15.0)

Examples

This example uses the OpenForPackage method to listen to notifications on the current package (Package.Current). The event handler acts on any optional package that has finished updating.

void RegisterForDeploymentNotifications()
{
    if (catalog == null)
    {
        catalog = PackageCatalog.OpenForPackage(Package.Current);
        catalog.PackageUpdating += OptionalPackageUpdatingCallback;
    }
}

void OptionalPackageUpdatingCallback(object sender, PackageUpdatingEventArgs args)
{
    if (args.IsComplete && args.TargetPackage.IsOptional)
    {
        // Let the user know the Optional package has updated, and can be used now
        var messageDialog = new MessageDialog(args.TargetPackage.DisplayName + 
                        " has been updated. Please restart the app to enjoy our latest features.");
    }
}

Remarks

This API requires the PackageQuery capability (unless the call is for the current package).

This API allows a package to listen to deployment notifications for another package and its dependents (like PWAs).

Applies to

See also