private static Task RequestExtendedExecutionAsync() { return(Task.Run(() => { lock (sessionSyncRoot) { if (extendedExeSession != null) { extendedExeSession.Dispose(); extendedExeSession = null; } var newSession = new ExtendedExecutionSession(); newSession.Reason = ExtendedExecutionReason.Unspecified; newSession.Revoked += ExtendedExecutionRevoked; var asyncTask = newSession.RequestExtensionAsync().AsTask(); asyncTask.Wait(); ExtendedExecutionResult result = asyncTask.Result; switch (result) { case ExtendedExecutionResult.Allowed: extendedExeSession = newSession; break; default: case ExtendedExecutionResult.Denied: newSession.Dispose(); break; } } })); }
public void Recreate() { if (_extendedExecutionSession != null) { _extendedExecutionSession.Revoked -= _extendedExecutionSession_Revoked; _extendedExecutionSession.Dispose(); } Create(); }
private static void Session_Revoked(object sender, ExtendedExecutionRevokedEventArgs args) { if (Session != null) { IsRequestExtensionSent = false; Session.Revoked -= Session_Revoked; Session.Dispose(); Session = null; } }
private async void BeginExtendedExecution() { // The previous Extended Execution must be closed before a new one can be requested. ClearExtendedExecution(); var newSession = new ExtendedExecutionSession(); newSession.Reason = ExtendedExecutionReason.Unspecified; newSession.Description = "Raising periodic toasts"; newSession.Revoked += SessionRevoked; ExtendedExecutionResult result = await newSession.RequestExtensionAsync(); switch (result) { case ExtendedExecutionResult.Allowed: session = newSession; break; default: case ExtendedExecutionResult.Denied: newSession.Dispose(); //建立Toast通知 string title = "Pixiv Wallpaper for Windows 10活动被禁止"; string content = "由于系统限制,应用程序无法在后台继续活动。"; ToastManagement tm = new ToastManagement(title, content, ToastManagement.ErrorMessage); tm.ToastPush(120); break; } }
private async void BeginExtendedExecution() { // The previous Extended Execution must be closed before a new one can be requested. // This code is redundant here because the sample doesn't allow a new extended // execution to begin until the previous one ends, but we leave it here for illustration. ClearExtendedExecution(); var newSession = new ExtendedExecutionSession(); newSession.Reason = ExtendedExecutionReason.Unspecified; newSession.Description = "Running time in the background"; newSession.Revoked += SessionRevoked; var result = await newSession.RequestExtensionAsync(); switch (result) { case ExtendedExecutionResult.Allowed: session = newSession; break; default: case ExtendedExecutionResult.Denied: newSession.Dispose(); break; } }
private async void BeginExtendedExecution() { // The previous Extended Execution must be closed before a new one can be requested. // This code is redundant here because the sample doesn't allow a new extended // execution to begin until the previous one ends, but we leave it here for illustration. ClearExtendedExecution(); var newSession = new ExtendedExecutionSession(); newSession.Reason = ExtendedExecutionReason.Unspecified; newSession.Description = "Raising periodic toasts"; newSession.Revoked += SessionRevoked; ExtendedExecutionResult result = await newSession.RequestExtensionAsync(); switch (result) { case ExtendedExecutionResult.Allowed: rootPage.NotifyUser("Extended execution allowed.", NotifyType.StatusMessage); session = newSession; periodicTimer = new Timer(OnTimer, DateTime.Now, TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(10)); break; default: case ExtendedExecutionResult.Denied: rootPage.NotifyUser("Extended execution denied.", NotifyType.ErrorMessage); newSession.Dispose(); break; } UpdateUI(); }
private async void BeginExtendedExecution(uint interval) { // The previous Extended Execution must be closed before a new one can be requested. // This code is redundant here because the sample doesn't allow a new extended // execution to begin until the previous one ends, but we leave it here for illustration. ClearExtendedExecution(); var newSession = new ExtendedExecutionSession(); newSession.Reason = ExtendedExecutionReason.LocationTracking; newSession.Description = "Tracking your location"; newSession.Revoked += SessionRevoked; ExtendedExecutionResult result = await newSession.RequestExtensionAsync(); switch (result) { case ExtendedExecutionResult.Allowed: this.NotifyUser("Extended execution allowed. Please navigate away from this app.", NotifyType.StatusMessage); session = newSession; Geolocator geolocator = await StartLocationTrackingAsync(); periodicTimer = new Timer(OnTimer, geolocator, TimeSpan.FromSeconds(interval), TimeSpan.FromSeconds(interval)); break; default: case ExtendedExecutionResult.Denied: this.NotifyUser("Extended execution denied.", NotifyType.ErrorMessage); newSession.Dispose(); break; } //UpdateUI(); }
public async void ExtendExecution() { Debug.WriteLine("Attempting extension"); try { if (session != null) { session.Revoked -= Session_Revoked; session.Dispose(); session = null; } session = new ExtendedExecutionSession(); session.Reason = ExtendedExecutionReason.Unspecified; session.Revoked += Session_Revoked; ExtendedExecutionResult result = await session.RequestExtensionAsync(); switch (result) { case ExtendedExecutionResult.Allowed: break; default: case ExtendedExecutionResult.Denied: SessionRevoked = true; break; } } catch { } }
private async void BeginExtendedExecution() { // The previous Extended Execution must be closed before a new one can be requested. // This code is redundant here because the sample doesn't allow a new extended // execution to begin until the previous one ends, but we leave it here for illustration. ClearExtendedExecution(); var newSession = new ExtendedExecutionSession(); newSession.Reason = ExtendedExecutionReason.Unspecified; newSession.Description = "Raising periodic toasts"; newSession.Revoked += SessionRevoked; ExtendedExecutionResult result = await newSession.RequestExtensionAsync(); switch (result) { case ExtendedExecutionResult.Allowed: session = newSession; Debug.Log("Extended Execution started succesfully"); break; default: case ExtendedExecutionResult.Denied: newSession.Dispose(); Debug.Log("Extended Execution denied!"); break; } }
private async void BeginExtendedExecution() { // The previous Extended Execution must be closed before a new one can be requested. ClearExtendedExecution(); var newSession = new ExtendedExecutionSession(); newSession.Reason = ExtendedExecutionReason.Unspecified; newSession.Description = "Raising periodic toasts"; newSession.Revoked += SessionRevoked; ExtendedExecutionResult result = await newSession.RequestExtensionAsync(); switch (result) { case ExtendedExecutionResult.Allowed: session = newSession; break; default: case ExtendedExecutionResult.Denied: newSession.Dispose(); //建立Toast通知 string title = loader.GetString("ExtendedExecutionDenied"); string content = loader.GetString("ExtendedExcutionDeniedExplanation"); ToastMessage tm = new ToastMessage(title, content, ToastMessage.ToastMode.BatterySetting); tm.ToastPush(120); break; } }
private async Task BeginExtendedExecution() { if (ViewModel == null) { return; } ClearExtendedExecution(); var newSession = new ExtendedExecutionSession { Reason = ExtendedExecutionReason.LocationTracking, Description = "Tracking your location" }; newSession.Revoked += SessionRevoked; ExtendedExecutionResult result = await newSession.RequestExtensionAsync(); switch (result) { case ExtendedExecutionResult.Allowed: session = newSession; ViewModel.Geolocator.AllowsBackgroundUpdates = true; ViewModel.StartTrackingTripCommand.Execute(null); break; default: Acr.UserDialogs.UserDialogs.Instance.Alert("Unable to execute app in the background.", "Background execution denied.", "OK"); newSession.Dispose(); break; } }
private async void BeginExtendedExecution() { ClearExtendedExecution(); var newSession = new ExtendedExecutionSession { Reason = ExtendedExecutionReason.Unspecified, Description = "Keep Shokpod running in background" }; newSession.Revoked += ExtendedExecutionSession_RevokedAsync; ExtendedExecutionResult result = await newSession.RequestExtensionAsync(); switch (result) { case ExtendedExecutionResult.Allowed: MetroEventSource.ToastAsync("Request for background execution granted!"); extendedExecutionSession = newSession; break; default: case ExtendedExecutionResult.Denied: MetroEventSource.ToastAsync("Request for background execution denied!"); newSession.Dispose(); break; } }
private async void BeginExtendedExecution() { // https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/ExtendedExecution // The previous Extended Execution must be closed before a new one can be requested. // This code is redundant here because the sample doesn't allow a new extended // execution to begin until the previous one ends, but we leave it here for illustration. ClearExtendedExecution(); var newSession = new ExtendedExecutionSession(); newSession.Reason = ExtendedExecutionReason.Unspecified; newSession.Description = "Raising periodic timer ticks"; newSession.Revoked += SessionRevoked; ExtendedExecutionResult result = await newSession.RequestExtensionAsync(); switch (result) { case ExtendedExecutionResult.Allowed: _session = newSession; _periodicTimer = new Timer(OnTimer, DateTime.Now, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1)); break; default: case ExtendedExecutionResult.Denied: newSession.Dispose(); break; } }
private void SessionRevoked(object sender, ExtendedExecutionRevokedEventArgs args) { if (_session != null) { _session.Dispose(); _session = null; } }
public void StopTracking() { if (_session != null) { _session.Dispose(); _session = null; } }
private static void StopCurrentSession() { if (session != null) { session.Dispose(); session = null; } }
private void ClearExecutionSession(ExtendedExecutionSession session) { if (session != null) { session.Revoked -= SessionRevoked; session.Dispose(); } }
private void StopLocationExtensionSession() { if (session != null) { session.Dispose(); session = null; } }
void ClearExtendedExecution() { if (session != null) { session.Revoked -= SessionRevoked; session.Dispose(); session = null; } }
public void Create() { if (s_extendedExecutionSession != null) { s_extendedExecutionSession.Revoked -= HandleRevoked; s_extendedExecutionSession.Dispose(); } CreateInternal(); }
private void ClearExtendedExecution() { if (_extendedExecutionSession != null) { _extendedExecutionSession.Revoked -= OnExtendedExecutionSessionRevoked; _extendedExecutionSession.Dispose(); _extendedExecutionSession = null; } }
public void CancelExecutedExtension() { if (newSession != null) { newSession.Revoked -= NewSession_Revoked; newSession.Dispose(); newSession = null; } }
public static void CancelExtension() { if (extendedExecutionSession != null) { extendedExecutionSession.Dispose(); } IsExtensionEnabled = false; MemoryManager.AppMemoryUsageLimitChanging -= MemoryManager_AppMemoryUsageLimitChanging; }
void EndPusherEventReceptionSession() { if (pusherEventReceptionSession != null) { pusherEventReceptionSession.Revoked -= PusherEventReceptionSessionRevoked; pusherEventReceptionSession.Dispose(); pusherEventReceptionSession = null; } }
void ClearExtendedExecution() { if (extendedExecutionSession != null) { extendedExecutionSession.Revoked -= ExtendedExecutionSession_RevokedAsync; extendedExecutionSession.Dispose(); extendedExecutionSession = null; } }
private async void OnStartSync(CoreDispatcher dispatcher) { //#if DEBUG //await VoIPConnection.Current.ConnectAsync(); //#endif await Toast.RegisterBackgroundTasks(); try { TileUpdateManager.CreateTileUpdaterForApplication("App").Clear(); } catch { } try { ToastNotificationManager.History.Clear("App"); } catch { } #if DESKTOP_BRIDGE if (ApiInformation.IsTypePresent("Windows.ApplicationModel.FullTrustProcessLauncher")) { try { await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync(); } catch { // The app has been compiled without desktop bridge } } #endif if (_extendedSession == null && ApiInfo.IsFullExperience) { var session = new ExtendedExecutionSession { Reason = ExtendedExecutionReason.Unspecified }; var result = await session.RequestExtensionAsync(); if (result == ExtendedExecutionResult.Allowed) { _extendedSession = session; Logs.Logger.Info(Logs.Target.Lifecycle, "ExtendedExecutionResult.Allowed"); } else { session.Dispose(); Logs.Logger.Warning(Logs.Target.Lifecycle, "ExtendedExecutionResult.Denied"); } } }
static void StopLocationExtensionSession() { MainPage.messageBox("Extended session stoped"); //reinitialisze the session if (session != null) { session.Dispose(); session = null; } System.Diagnostics.Debug.WriteLine("Extended session stoped"); }
private static void ExtendedExecutionSession_Revoked(object sender, ExtendedExecutionRevokedEventArgs args) { try { if (session != null) { session.Dispose(); session = null; } } catch { } }
static void Create() { _isStarted = _isRevoked = false; _extendedExecutionSession?.Dispose(); _extendedExecutionSession = new ExtendedExecutionSession { Description = typeof(ExtendedServiceHelper).ToString(), }; _extendedExecutionSession.Revoked += (s, e) => { _isStarted = false; _isRevoked = true; }; }
private void ClearSession() { if (session != null) { session.Revoked -= Session_Revoked; session.Dispose(); session = null; } if (periodicTimer != null) { periodicTimer.Dispose(); periodicTimer = null; } }
private async Task BeginExtendedExecution() { if (ViewModel == null) return; ClearExtendedExecution(); try { var newSession = new ExtendedExecutionSession { Reason = ExtendedExecutionReason.LocationTracking, Description = "Tracking your location" }; newSession.Revoked += SessionRevoked; ExtendedExecutionResult result = await newSession.RequestExtensionAsync(); switch (result) { case ExtendedExecutionResult.Allowed: session = newSession; ViewModel.Geolocator.AllowsBackgroundUpdates = true; ViewModel.StartTrackingTripCommand.Execute(null); break; default: Acr.UserDialogs.UserDialogs.Instance.Alert("Unable to execute app in the background.", "Background execution denied.", "OK"); newSession.Dispose(); break; } } catch (Exception ex) { // Sometimes while creating ExtendedExecution session you get Resource not ready exception. Logger.Instance.Report(ex); Acr.UserDialogs.UserDialogs.Instance.Alert("Will not be able to execute app in the background.", "Background execution session failed.", "OK"); } }
private async void BeginExtendedExecution() { // The previous Extended Execution must be closed before a new one can be requested. // This code is redundant here because the sample doesn't allow a new extended // execution to begin until the previous one ends, but we leave it here for illustration. ClearExtendedExecution(); var newSession = new ExtendedExecutionSession(); newSession.Reason = ExtendedExecutionReason.Unspecified; newSession.Description = "Running multiple tasks"; newSession.Revoked += SessionRevoked; ExtendedExecutionResult result = await newSession.RequestExtensionAsync(); switch (result) { case ExtendedExecutionResult.Allowed: rootPage.NotifyUser("Extended execution allowed.", NotifyType.StatusMessage); session = newSession; break; default: case ExtendedExecutionResult.Denied: rootPage.NotifyUser("Extended execution denied.", NotifyType.ErrorMessage); newSession.Dispose(); break; } UpdateUI(); if (session != null) { cancellationTokenSource = new CancellationTokenSource(); // Start up a few tasks that all share this session. using (var deferral = GetExecutionDeferral()) { var random = new Random(); for (int i = 0; i < 3; i++) { RaiseToastAfterDelay(i, random.Next(5, 10)); } } } }
private async void BeginExtendedExecution() { // The previous Extended Execution must be closed before a new one can be requested. // This code is redundant here because the sample doesn't allow a new extended // execution to begin until the previous one ends, but we leave it here for illustration. ClearExtendedExecution(); var newSession = new ExtendedExecutionSession(); newSession.Reason = ExtendedExecutionReason.LocationTracking; newSession.Description = "Tracking your location"; newSession.Revoked += SessionRevoked; ExtendedExecutionResult result = await newSession.RequestExtensionAsync(); switch (result) { case ExtendedExecutionResult.Allowed: rootPage.NotifyUser("Extended execution allowed.", NotifyType.StatusMessage); session = newSession; Geolocator geolocator = await StartLocationTrackingAsync(); periodicTimer = new Timer(OnTimer, geolocator, TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(10)); break; default: case ExtendedExecutionResult.Denied: rootPage.NotifyUser("Extended execution denied.", NotifyType.ErrorMessage); newSession.Dispose(); break; } UpdateUI(); }