private async Task PreventFromSuspending() { ExtendedExecutionForegroundSession newSession = new ExtendedExecutionForegroundSession(); newSession.Reason = ExtendedExecutionForegroundReason.Unconstrained; newSession.Revoked += SessionRevoked; ExtendedExecutionForegroundResult result = await newSession.RequestExtensionAsync(); switch (result) { case ExtendedExecutionForegroundResult.Allowed: _session = newSession; break; default: case ExtendedExecutionForegroundResult.Denied: newSession.Dispose(); break; } }
private async void ExtendedExecutionRequestAsync() { var newSession = new ExtendedExecutionForegroundSession(); newSession.Reason = ExtendedExecutionForegroundReason.Unconstrained; newSession.Description = "Long Running Processing"; //newSession.Revoked += SessionRevoked; ExtendedExecutionForegroundResult result = await newSession.RequestExtensionAsync(); switch (result) { case ExtendedExecutionForegroundResult.Allowed: break; default: case ExtendedExecutionForegroundResult.Denied: break; } }
/// <summary> /// Initialize or clean up the camera and our UI, /// depending on the page state. /// </summary> /// <returns></returns> private async Task SetUpBasedOnStateAsync() { Debug.WriteLine("Entering SetupBasedOnStateAsync(): " + new System.Diagnostics.StackTrace().ToString()); // Avoid reentrancy: Wait until nobody else is in this function. while (!_setupTask.IsCompleted) { await _setupTask; } // We want our UI to be active if // * We are the current active page. // * The window is visible. // * The app is not suspending. bool show = _isActivePage && Window.Current.Visible && !_isSuspending; if (_previewVideoEnabled != show) { _previewVideoEnabled = show; PreviewToggleSwitch.IsOn = show; } Func <Task> setupAsync = async() => { //if(!show) if (_isSuspending) { Debug.WriteLine("SetupBasedOnStateAsync - shutting down!"); _setupBasedOnState = false; await ShutdownAsync(); await StopServer(); } else if (!_setupBasedOnState) { Debug.WriteLine("SetupBasedOnStateAsync - setting up!"); _setupBasedOnState = true; ExtendedExecutionForegroundSession newSession = new ExtendedExecutionForegroundSession(); newSession.Reason = ExtendedExecutionForegroundReason.Unconstrained; newSession.Description = "Long Running Processing"; newSession.Revoked += SessionRevoked; ExtendedExecutionForegroundResult result = await newSession.RequestExtensionAsync(); switch (result) { case ExtendedExecutionForegroundResult.Allowed: Debug.WriteLine("Extended Execution in Foreground ALLOWED."); _extendedExecutionSession = newSession; break; default: case ExtendedExecutionForegroundResult.Denied: Debug.WriteLine("Extended Execution in Foreground DENIED."); break; } await MJPEGStreamerInitAsync(); await InitializeCameraAsync(); await StartServer(); // Prevent the device from sleeping while running _displayRequest.RequestActive(); } }; Debug.WriteLine("SetupBasedOnStateAsync -calling setup Async!"); _setupTask = setupAsync(); Debug.WriteLine("SetupBasedOnStateAsync -setup Async called!"); await _setupTask; Debug.WriteLine("SetupBasedOnStateAsync - awaited setup task!"); UpdateCaptureControls(); }