12/2/2018 12:23 PM APP-410T Real time communication: keep your Metro style app connected whether it is running or suspended Raghu Gatta Principal Development Lead Microsoft Corporation Kamal Srinivasan Program Manager Microsoft Corporation © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Agenda Real Time Communication (RTC) app requirements User in control of the RTC apps Building your RTC app in Windows 8 You’ll leave knowing how to Build communication apps that work 24x7
Customer promise in Windows 8 Longer battery life Always reachable apps
Review app process lifetime Running App Suspended App Terminated App Suspending Low Memory Resuming
RTC apps that need to be always reachable What about RTC apps? VoIP IM Mail RTC apps that need to be always reachable
Windows enables you to develop apps that are always reachable!
The app lifecycle …with RTC apps Background Task Executes Background Running App Suspended App Terminated App Suspending Low Memory Resuming
Running an app in the background 12/2/2018 12:23 PM demo Chat app (PingMe) Running an app in the background © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
RTC trigger APIs for your apps OS VoIP IM Mail Network Trigger System Trigger Time Trigger Background Task Infrastructure
Building an always reachable IM app
Building an IM app on Windows 8 Network Trigger System Trigger Time Trigger Background Task Infrastructure VoIP IM Mail Network Trigger System Trigger Receive an IM when app is in the background Receive an IM after user logs in
Execution Pattern App registers for trigger OS waits Trigger fires Background task executes
Register for IM network trigger Open your socket using Windows.Networking.Sockets; StreamSocket sock = new StreamSocket(); // Connect the streamsocket … // Create a Notification Channel with Push capability NotificationChannel nc = new NotificationChannel( "channelOne", “MyApp.Background.KeepAliveTask", “MyApp.Background.PushNotifyTask", ServerKATimeInMins); Add Control Channel metadata // Associate the socket with the notification channel channelStatus = nc.UsingTransport(sock); Register your socket © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
App execution upon receiving IM Network Trigger App execution upon receiving IM using Windows.ApplicationModel.Background; public sealed class PushNotifyTask : IBackgroundTask { public void Run(IBackgroundTaskInstance taskInstance) { // Handle Incoming message // Throwing a toast code } © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Keep Alive maintains your control channel Network Keep alive Interval Server Keep alive Interval
App execution on Keep Alive Network Trigger App execution on Keep Alive using Windows.ApplicationModel.Background; public sealed class KeepAliveTask : IBackgroundTask { public void Run(IBackgroundTaskInstance taskInstance) { // Send Keepalive message to remote server } }} © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Register on User Login using Windows.ApplicationModel.Background; System Trigger Register on User Login Create user login trigger using Windows.ApplicationModel.Background; // Specify the trigger IBackgroundTrigger trigger = new SystemTrigger(SystemTriggerType.SessionStart, false); Associate trigger with app code // Associate app code with the trigger BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder(); taskBuilder.TaskEntryPoint = “MyApp.Background.RegisterForUserLogin"; taskBuilder.SetTrigger(trigger); taskBuilder.Name = “OnUserPresent"; Register trigger // Register the task for background execution IBackgroundTaskRegistration taskRegistration = taskBuilder.Register(); © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
App execution on User Login System Trigger App execution on User Login using Windows.ApplicationModel.Background; public sealed class RegisterForUserLogin: IBackgroundTask { public void Run(IBackgroundTaskInstance taskInstance) { // Your app code to create notification channel } © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Receive an IM when in “Connected Standby” 12/2/2018 12:23 PM demo Chat app (PingMe) Receive an IM when in “Connected Standby” © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Always connected Mobile broadband (e.g. 3G, 4G, LTE, etc.) Network Connectivity
How does this work in connected standby?
Nothing special, one model to stay connected.
Building a POP mail client with periodic updates
Building a POP mail app on Windows 8 Network Trigger System Trigger Time Trigger Background Task Infrastructure VoIP IM Mail Time Trigger Periodic Mail Sync
Register for Periodic Mail Sync Time Trigger Register for Periodic Mail Sync Create time trigger using Windows.ApplicationModel.Background; // Specify the trigger TimeTrigger trigger = new TimeTrigger(UpdateInterval, Periodic); Associate trigger with app code // Associate app code with the trigger BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder(); taskBuilder.TaskEntryPoint = “MyApp.Background.UpdateEmailTask"; taskBuilder.SetTrigger(trigger); taskBuilder.Name = “TimerExpiry"; Register trigger // Register the task for background execution IBackgroundTaskRegistration taskRegistration = taskBuilder.Register(); © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
App execution upon timer expiry Time Trigger App execution upon timer expiry using Windows.ApplicationModel.Background; public sealed class UpdateEmailTask : IBackgroundTask { public void Run(IBackgroundTaskInstance taskInstance) { // Your app code to update email } © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Review
Key points Longer Battery Life Always Reachable Apps
Write your RTC app code using background tasks. Key points Write your RTC app code using background tasks. Your app will be always reachable in connected standby.
Related sessions [APP-409T] Fundamentals of Metro style apps: how and when your app will run [HW-456T] Understanding Connected Standby [HW-566T] Networking for connected standby [PLAT-785T] Creating connected apps that work on today's networks [APP-396T] Using tiles and notifications
Further reading and documentation Introduction to Background Tasks http://go.microsoft.com/fwlink/?LinkID=227329&clcid=0x409 Contact info – AskRtcDev@microsoft.com (optional)
thank you Feedback and questions http://forums.dev.windows.com Session feedback http://bldw.in/SessionFeedback
12/2/2018 12:23 PM © 2011 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. © 2011 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Backup
Lock Screen API sample void AddToLockScreen() { IAsyncOperation<LockScreenState> operation = LockScreen.AddToLockScreenAsync(); operation.Completed = OnAddToLockScreenOperationCompleted; operation.Start(); } void OnAddToLockScreenOperationCompleted(IAsyncOperation<LockScreenState> operation) { if (operation.Status == AsyncStatus.Completed) { LockScreenState result = operation.GetResults(); switch (result) { case LockScreenState.NotOnLockScreen: break; case LockScreenState.OnLockScreen: case LockScreenState.DefaultNotOnLockScreen: } } else if (operation.Status == AsyncStatus.Error){ // Report error © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Registering for Network Change System Event Registering for Network Change using Windows.ApplicationModel.Background; // Specify the trigger IBackgroundTrigger trigger = new SystemTrigger(SystemTriggerType.NetworkStateChange, false); // Associate app code with the trigger BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder(); taskBuilder.TaskEntryPoint = “MyAppBackground.NetworkStateChangeTask"; taskBuilder.SetTrigger(trigger); taskBuilder.Name = “OnNetworkStateChange"; // Register the task for background execution IBackgroundTaskRegistration taskRegistration = taskBuilder.Register(); © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
App execution upon network change System Event App execution upon network change using Windows.ApplicationModel.Background; public sealed class NetworkStateChangeTask : IBackgroundTask { public void Run(IBackgroundTaskInstance taskInstance) { // Re-register Notification Channel } © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.