Note that there are some explanatory texts on larger screens.

plurals
  1. POWindows Phone ScheduleAgent grabbing images on set period
    primarykey
    data
    text
    <p>I'm attempting to follow an <a href="http://developer.nokia.com/Community/Wiki/Dynamic_Lock_Screen_for_Windows_Phone_8" rel="nofollow">Windows Phone tutorial</a>, tweaking it a bit to fit my needs. I am trying to grab a new picture every X seconds (30 for debugging) and set it as the new lockscreen background. I created a ScheduleAgent object to call it, however, it seems to be skipping a function. It <i>does not</i> skip this when in the <code>MainPage.xaml.cs</code>, which runs the exact same function.</p> <p><strong>ScheduleAgent.cs</strong></p> <pre><code> static ScheduledAgent() { ....&lt;irrelevant code&gt;.... protected override void OnInvoke(ScheduledTask task) { .... &lt; Code went here that shouldn't matter &gt; .... } Debug.WriteLine("Imagename = " + imageName); DownloadImagefromServer("https://s3-us-west-2.amazonaws.com/qoutescreen/0" + imageName + ".jpg"); </code></pre> <p>m.ReleaseMutex(); }</p> <pre><code> // If debugging is enabled, launch the agent again in one minute. // debug, so run in every 30 secs #if(DEBUG_AGENT) ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(30)); System.Diagnostics.Debug.WriteLine("Periodic task is started again: " + task.Name); #endif // Call NotifyComplete to let the system know the agent is done working. NotifyComplete(); } //=============================================================================== 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(schema + 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()); } } private async Task DownloadImagefromServer(string imgUrl) { Debug.WriteLine("Attempting to Get Image from Server..."); WebClient client = new WebClient(); try { // I GET A "Cannot await Void" problem here?!?!? //================================================================= var result = await client.OpenReadAsync(new Uri(imgUrl, UriKind.Absolute)); BitmapImage bitmap = new BitmapImage(); bitmap.SetSource(result); return result; } catch (Exception e) { Debug.WriteLine(e); } client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted); //client.OpenReadAsync(new Uri(imgUrl, UriKind.Absolute)); } //------------------------------------------------------------------ //THIS FUNCTION IS NEVER HIT WHEN RUN IN THE ScheduleAgent.cs CODE, HOWEVER // WHEN IT IS RUN INT HE MainPage.xaml.cs CODE (Which is a copy/paste) IT RUNS FINE // WHY IS IT NOT HITTING THIS? HOW CAN I FIX IT? //------------------------------------------------------------------ void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) { BitmapImage bitmap = new BitmapImage(); bitmap.SetSource(e.Result); //img.Source = bitmap; // Create a filename for JPEG file in isolated storage. String tempJPEG = "DownloadedWalleper.jpg"; // Create virtual store and file stream. Check for duplicate tempJPEG files. using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) { if (myIsolatedStorage.FileExists(tempJPEG)) { myIsolatedStorage.DeleteFile(tempJPEG); } IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(tempJPEG); StreamResourceInfo sri = null; Uri uri = new Uri(tempJPEG, UriKind.Relative); sri = Application.GetResourceStream(uri); //BitmapImage bitmap = new BitmapImage(); //bitmap.SetSource(sri.Stream); WriteableBitmap wb = new WriteableBitmap(bitmap); // Encode WriteableBitmap object to a JPEG stream. Extensions.SaveJpeg(wb, fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85); //wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85); fileStream.Close(); } LockScreenChange("DownloadedWalleper.jpg", false); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload