private ResourceIntensiveTask resourceIntensiveTask; private string resourceIntensiveTaskName = "SmartLockScreenScheduledTaskAgent"; private string resourceIntensiveTaskDescription = "Displays the latest deals."; private StartTask() { LockScreenChange("ms-appdata:///Local/Image0.jpg", true); } private async void LockScreenChange(string filePathOfTheImage, bool isAppResource) { if (!LockScreenManager.IsProvidedByCurrentApplication) { // If you're not the provider, this call will prompt the user for permission. // Calling RequestAccessAsync from a background agent is not allowed. await LockScreenManager.RequestAccessAsync(); } // Only do further work if the access is granted. if (LockScreenManager.IsProvidedByCurrentApplication) { // At this stage, the app is the active lock screen background provider. // The following code example shows the new URI schema. // ms-appdata points to the root of the local app data folder. // ms-appx points to the Local app install folder, to reference resources bundled in the XAP package // var schema = isAppResource ? "ms-appx:///" : "ms-appdata:///Local/"; var uri = new Uri(filePathOfTheImage, UriKind.Absolute); // Set the lock screen background image. LockScreen.SetImageUri(uri); // Get the URI of the lock screen background image. var currentImage = LockScreen.GetImageUri(); System.Diagnostics.Debug.WriteLine("The new lock screen background image is set to {0}", currentImage.ToString()); UpdatePrimaryTile(); StartResourceIntensiveAgent();// StartPeriodicAgent();// // MessageBox.Show("Lock screen changed. Click F12 or go to lock screen."); } else { MessageBox.Show("Background can't be updated as you clicked no!!"); } } public void RemoveResourceIntensiveAgent() { try { if (resourceIntensiveTask != null) { ScheduledActionService.Remove(resourceIntensiveTaskName); } } catch (Exception) { } } /// <summary> /// Code to start the resource intensive task /// </summary> private void StartResourceIntensiveAgent() { // Variable for tracking enabled status of background agents for this app. agentsAreEnabled = true; resourceIntensiveTask = ScheduledActionService.Find(resourceIntensiveTaskName) as ResourceIntensiveTask; // If the task already exists and background agents are enabled for the // application, you must remove the task and then add it again to update // the schedule. if (resourceIntensiveTask != null) { ScheduledActionService.Remove(resourceIntensiveTaskName); } resourceIntensiveTask = new ResourceIntensiveTask(resourceIntensiveTaskName); // The description is required for periodic agents. This is the string that the user // will see in the background services Settings page on the device. resourceIntensiveTask.Description = (resourceIntensiveTaskDescription); // Place the call to Add in a try block in case the user has disabled agents. try { ScheduledActionService.Add(resourceIntensiveTask); //ResourceIntensiveStackPanel.DataContext = resourceIntensiveTask; resourceIntensiveTask.ExpirationTime = DateTime.Now.AddDays(14); // If debugging is enabled, use LaunchForTest to launch the agent in one minute. ScheduledActionService.LaunchForTest(resourceIntensiveTaskName, TimeSpan.FromSeconds(30)); } catch (InvalidOperationException exception) { if (exception.Message.Contains("BNS Error: The action is disabled")) { MessageBox.Show("Background agents for this application have been disabled by the user."); agentsAreEnabled = false; } } catch (SchedulerServiceException) { // No user action required. } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)