共用方式為


AppListEntry.LaunchForUserAsync(User) 方法

定義

在指定使用者的內容中啟動與此 AppListEntry 相關聯的應用程式。

public:
 virtual IAsyncOperation<bool> ^ LaunchForUserAsync(User ^ user) = LaunchForUserAsync;
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperation<bool> LaunchForUserAsync(User const& user);
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperation<bool> LaunchForUserAsync(User user);
function launchForUserAsync(user)
Public Function LaunchForUserAsync (user As User) As IAsyncOperation(Of Boolean)

參數

user
User

應用程式應該啟動的使用者內容。

傳回

如果啟動成功,則傳回 true ;否則為 false

屬性

Windows 需求

裝置系列
Windows 10, version 1803 (已於 10.0.17134.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v6.0 引進)

範例

public async void LaunchButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
    // The active User is retrieved from the initial activation args and validated against list of active users
    User user = this.GetAppActiveUser();
    PackageManager pm = new PackageManager();
    // The App Family Name is stored as part of the Product Display Page
    Package p = pm.FindPackage(this.GetFocusedAppFamilyName());
    IReadOnlyList<AppListEntry> entries = await p.GetAppListEntriesAsync();

    //This assumes the first app in the package should be launched, if there is one in the package
    if (entries.Count > 0)
    {
        await entries[0].LaunchForUserAsync(user);
    }
}

備註

這是多使用者感知 (MUA) API,而且只能供宣告自己為 MUA 的應用程式使用,而且只能在支援 MUA 應用程式的裝置上使用。 應用程式是以相同的方式啟動,就像指定使用者按一下應用程式清單中的專案一樣。 使用者會透過事件引數傳遞至已啟動的應用程式。 傳遞 nulluser 會導致例外狀況。

MUA 應用程式會以預設使用者內容啟動。 值 user 會透過事件引數傳遞至啟動的應用程式,表示應用程式代表誰啟動。 單一使用者感知應用程式會在傳入此 API 的值內容 user 中啟動。

適用於

另請參閱