RemoteSystemSession 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示并处理可在两个或多个连接的设备之间共享的远程会话。 有关此功能的信息,请参阅备注。
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
- 继承
- 属性
- 实现
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() |
执行与释放或重置非托管资源关联的应用程序定义的任务。 |
SendInvitationAsync(RemoteSystem) |
邀请给定的远程设备加入此远程会话。 |
事件
Disconnected |
此设备已从此远程会话断开连接时引发。 |