Page 29 - MSDN Magazine, May 2018
P. 29

is concerned only when a participant leaves the session. The host will be notified directly by the participant when they join, as you’ll see later in the article. Participants only need to determine the current host account.
The session manager maintains a participant watcher as a private variable that’s initialized in the InitParticipantWatcher.
The last thing the CreateSession method needs added to the class is an event to let consumers know if and when the session is disconnected. The new SessionDisconnected event can be defined as follows:
public event EventHandler<RemoteSystemSessionDisconnectedEventArgs> SessionDisconnected =
delegate { };
Joining a Session
Now that the app is able to broadcast a new remote session, the next thing to implement is the ability to join that session from another machine. There are two steps to joining a remote session: discovery and then connecting to the session.
Discovering a Session An app is able to discover nearby remote sessions through the RemoteSystemSessionWatcher, which is cre- ated from the static CreateWatcher method. This class raises events every time a session is added or removed. Add a new method— DiscoverSessions—to the RemoteSessionManager. This method will create a RemoteSystemSessionWatcher as a private variable to the class and handle the Added and Removed events. These events will be wrapped by two new events added to RemoteSessionManager:
Figure 8 Discovering Sessions
private RemoteSystemSessionWatcher _watcher;
public event EventHandler<RemoteSystemSessionInfo> SessionAdded = delegate { }; public event EventHandler<RemoteSystemSessionInfo> SessionRemoved = delegate { };
public async Task<bool> DiscoverSessions() {
RemoteSystemAccessStatus status = await RemoteSystem.RequestAccessAsync(); if (status != RemoteSystemAccessStatus.Allowed)
{
return false; }
_watcher = RemoteSystemSession.CreateWatcher(); _watcher.Added += (sender, args) =>
{
SessionAdded(sender, args.SessionInfo); };
_watcher.Removed += (sender, args) => {
SessionRemoved(sender, args.SessionInfo); };
_watcher.Start();
return true; }
msdnmagazine.com
Seeking for professional and easy-to-use Imaging .NET SDK?
VintaSoft Imaging .NET SDK
Load, view, convert, manage, print, capture from camera, save raster images and PDF documents.
Image Viewer for .NET, WPF and WEB
100+ Image Processing and Document Cleanup commands
PDF Reader, Writer, Visual Editor Image Annotations
JBIG2 and JPEG2000 codecs OCR and Document Recognition Forms Processing and OMR DICOM decoder
Barcode Reader and Generator TWAIN scanning
Free evaluation version
Royalty free licensing
www.vintasoft.com VintaSoft is the registered trademark
of VintaSoft Ltd.


































































































   27   28   29   30   31