共用方式為


RemoteSystemSession 類別

定義

表示及處理可在兩部或更多連線裝置之間共用的遠端會話。 如需此功能的相關資訊,請參閱。

public ref class RemoteSystemSession sealed : IClosable
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 262144)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class RemoteSystemSession final : IClosable
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 262144)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class RemoteSystemSession : System.IDisposable
Public NotInheritable Class RemoteSystemSession
Implements IDisposable
繼承
Object Platform::Object IInspectable RemoteSystemSession
屬性
實作

Windows 需求

裝置系列
Windows 10 Creators Update (已於 10.0.15063.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v4.0 引進)
應用程式功能
remoteSystem

範例

請參閱下列程式碼範例,以取得遠端會話 (的程式,包括取得 RemoteSystemSession 實例) 的參考。

public async void JoinExistingSession() {

    // request to join. sessionInfo has already been selected by user.
    RemoteSystemSessionJoinResult joinResult = await sessionInfo.JoinAsync();

    // process the result
    if (joinResult.Status == RemoteSystemSessionJoinStatus.Success) {

        // if the join was successful, acquire a reference to the session
        currentSession = joinResult.Session;

        // optionally handle the disconnected event
        currentSession.Disconnected += async (sender, args) => {
            // update the UI, using args.Reason
        };

        // update the UI with the session.DisplayName and 
        // session.ControllerDisplayName strings. Save a reference to 
        // this RemoteSystemSession, to use when the user selects
        // this session from the UI

    } else {
        // join request failed. optionally update UI
    }
}

或者,如需如何建立遠端會話及處理聯結要求的範例,請參閱下列程式碼。

public async void StartNewSharedExperience() {

    var manager = new RemoteSystemSessionController("Bob’s Minecraft game");

    // register the following code to handle the JoinRequested event
    manager.JoinRequested += async (sender, args) => {
        // Get the deferral
        var deferral = args.GetDeferral();

        // display the participant (args.JoinRequest.Participant) on UI, giving the 
        // user an opportunity to respond
        // ...

        // If the user chooses "accept", accept this remote system as a participant
        args.JoinRequest.Accept();
    };

    // create and start the session
    RemoteSystemSessionCreationResult createResult = await manager.CreateSessionAsync();

    // handle the creation result
    if (createResult.Status == RemoteSystemSessionCreationStatus.Success) {
        // creation was successful
        RemoteSystemSession currentSession = createResult.Session;

        // optionally subscribe to the disconnection event
        currentSession.Disconnected += async (sender, args) => {
            // update the UI, using args.Reason
            // ...
        };

        // Use session ...

    } else if (createResult.Status == RemoteSystemSessionCreationStatus.SessionLimitsExceeded) {
        // creation failed. Optionally update UI to indicate that there are too many sessions in progress
    } else {
        // creation failed for an unknown reason. Optionally update UI
    }
}

備註

遠端系統會話是更廣泛的遠端系統功能集的一部分。 它可讓應用程式建立會話物件做為中繼協力廠商,讓兩個或多個裝置可以持續透過通訊,啟用一些新的跨裝置案例,例如遠端應用程式傳訊。

已聯結的會話是由 RemoteSystemSession 物件表示。 已知但尚未聯結的會話是由 RemoteSystemSessionInfo 物件表示。

屬性

ControllerDisplayName

取得此遠端會話控制器之裝置的電腦名稱稱。

DisplayName

取得這個遠端會話的公開名稱,由會話的控制器指定。

Id

取得這個遠端會話的唯一識別碼。

方法

Close()

關閉會話,中斷所有參與者的連線。

CreateParticipantWatcher()

初始化 RemoteSystemSessionParticipantWatcher 來監視此遠端會話的參與者。

CreateWatcher()

初始化並傳回 RemoteSystemSessionWatcher 物件,以監視遠端會話是否存在。

Dispose()

執行與釋放 (Free)、釋放 (Release) 或重設 Unmanaged 資源相關聯之應用程式定義的工作。

SendInvitationAsync(RemoteSystem)

邀請指定的遠端裝置加入此遠端會話。

事件

Disconnected

當此裝置已從這個遠端會話中斷連線時引發。

適用於