/// <summary>
        /// Fired when we should load the content.
        /// </summary>
        /// <param name="source"></param>
        public void OnPrepareContent()
        {
            // Run our work on a background thread.
            Task.Run(() =>
            {
                // Get the image Url
                string imageUrl = ImageManager.GetImageUrl(m_base.Source.Url);

                // Make sure we got it.
                if (String.IsNullOrWhiteSpace(imageUrl))
                {
                    // This is bad, we should be able to get the url.
                    App.BaconMan.TelemetryMan.ReportUnExpectedEvent(this, "BasicImageControlNoImageUrl");

                    // Jump back to the UI thread
                    m_base.FireOnFallbackToBrowser();
                    return;
                }

                // Make sure we aren't destroyed.
                if (m_base.IsDestoryed)
                {
                    return;
                }

                // Fire off a request for the image.
                ImageManager.ImageManagerRequest request = new ImageManager.ImageManagerRequest()
                {
                    ImageId = m_base.Source.Id,
                    Url     = imageUrl
                };
                request.OnRequestComplete += OnRequestComplete;
                App.BaconMan.ImageMan.QueueImageRequest(request);
            });
        }
        /// <summary>
        /// Callback when we get the image.
        /// </summary>
        /// <param name="response"></param>
        public async void OnRequestComplete(object sender, ImageManager.ImageManagerResponseEventArgs response)
        {
            // Remove the event
            ImageManager.ImageManagerRequest request = (ImageManager.ImageManagerRequest)sender;
            request.OnRequestComplete -= OnRequestComplete;

            // Jump back to the UI thread
            await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                if (!response.Success)
                {
                    App.BaconMan.TelemetryMan.ReportUnExpectedEvent(this, "BasicImageControlNoImageUrl");
                    m_base.FireOnFallbackToBrowser();
                    return;
                }

                lock (this)
                {
                    if (m_base.IsDestoryed)
                    {
                        // Get out of here if we should be destroyed.
                        return;
                    }

                    // Set the current size of the control, this will also be set
                    // by the size changed listener but we want to make sure it is correct.
                    m_currentControlSize.Height = ui_contentRoot.ActualHeight;
                    m_currentControlSize.Width  = ui_contentRoot.ActualWidth;

                    // Grab the source, we need this to make the image
                    m_imageSourceStream = response.ImageStream;

                    // Add the image to the UI
                    m_image = new Image();

                    // Add a loaded listener so we can size the image when loaded
                    m_image.Loaded += Image_Loaded;

                    // Set the image.
                    ReloadImage(false);

                    // Set the image into the UI.
                    ui_scrollViewer.Content = m_image;

                    // Setup the save image tap
                    m_image.RightTapped += ContentRoot_RightTapped;
                    m_image.Holding     += ContentRoot_Holding;

                    m_base.FireOnLoading(false);
                }
            });
        }
        public async void OnRequestComplete(object sender, ImageManager.ImageManagerResponseEventArgs response)
        {
            // Remove event
            ImageManager.ImageManagerRequest request = (ImageManager.ImageManagerRequest)sender;
            request.OnRequestComplete -= OnRequestComplete;

            // Make sure we were successfully.
            if (!response.Success)
            {
                return;
            }

            // Get a unique name for this image
            int imageCount = 0;

            lock (m_getImageLock)
            {
                imageCount = m_imageReturnCount;
                m_imageReturnCount++;
            }

            // Get the file name
            string imageFileName = imageCount + ".jpg";

            try
            {
                // Write the file
                await WriteImageToFile(response.ImageStream, imageFileName, m_isCurrentImageRequestLockScreen);
            }
            catch (Exception e)
            {
                m_baconMan.MessageMan.DebugDia("Failed to write background image", e);
                m_baconMan.TelemetryMan.ReportUnExpectedEvent(this, "Failed to write background image", e);
            }

            // Add the file to the list
            lock (m_getImageLock)
            {
                // Report we are done
                m_imageDoneCount++;

                // Check to see if we were last
                if (m_imageDoneCount == c_maxImageCacheCount)
                {
                    m_autoReset.Set();
                }
            }
        }
        /// <summary>
        /// Callback when we get the image.
        /// </summary>
        /// <param name="response"></param>
        public async void OnRequestComplete(object sender, ImageManager.ImageManagerResponseEventArgs response)
        {
            // Remove the event
            ImageManager.ImageManagerRequest request = (ImageManager.ImageManagerRequest)sender;
            request.OnRequestComplete -= OnRequestComplete;

            // Jump back to the UI thread
            await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                if (!response.Success)
                {
                    App.BaconMan.TelemetryMan.ReportUnExpectedEvent(this, "BasicImageControlNoImageUrl");
                    m_host.FallbackToWebBrowser(m_post);
                    return;
                }

                lock (m_host)
                {
                    if (m_isDestoryed)
                    {
                        // Get out of here if we should be destroyed.
                        return;
                    }

                    // Create a bitmap and set the source
                    // #todo, initially we can use a bitmap here decoded to the size of the control
                    // then when the user zooms in we can swap it for a larger image.
                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.SetSource(response.ImageStream);

                    // Add the image to the UI
                    m_image = new Image();

                    // Add a loaded listener so we can size the image when loaded
                    m_image.Loaded += Image_Loaded;

                    // Set the image.
                    m_image.Source = bitmapImage;

                    // Set the image into the UI.
                    ui_scrollViewer.Content = m_image;

                    // Setup the save image tap
                    m_image.RightTapped += ContentRoot_RightTapped;
                    m_image.Holding     += ContentRoot_Holding;
                }
            });
        }
        /// <summary>
        /// THREAD BLOCKING Given a list of post this gets the images and puts them into file cache.
        /// </summary>
        /// <param name="posts"></param>
        /// <param name="isLockScreen"></param>
        /// <returns></returns>
        private bool GetImagesFromPosts(List <Post> posts, bool isLockScreen)
        {
            // First, remove all of the existing images
            using (AutoResetEvent aEvent = new AutoResetEvent(false))
            {
                Task.Run(async() => { await DeleteAllCacheImages(isLockScreen); aEvent.Set(); });
                aEvent.WaitOne();
            }

            // Reset the wait event
            m_autoReset.Reset();

            // Setup vars
            m_reqeustCount     = 0;
            m_imageReturnCount = 0;
            m_imageDoneCount   = 0;
            m_isCurrentImageRequestLockScreen = isLockScreen;

            // Make request for the images
            foreach (Post post in posts)
            {
                string imageUrl = ImageManager.GetImageUrl(post.Url);
                if (!String.IsNullOrWhiteSpace(imageUrl))
                {
                    // Make the request
                    ImageManager.ImageManagerRequest request = new ImageManager.ImageManagerRequest()
                    {
                        Url     = imageUrl,
                        ImageId = post.Id
                    };
                    request.OnRequestComplete += OnRequestComplete;
                    m_baconMan.ImageMan.QueueImageRequest(request);
                    m_reqeustCount++;
                }

                if (m_reqeustCount > c_maxImageCacheCount)
                {
                    break;
                }
            }

            // Wait for all of the images to be downloaded and stored.
            m_autoReset.WaitOne(10000);

            // See if we got all of the requests, then we are successful.
            return(m_imageDoneCount >= (c_maxImageCacheCount - 2));
        }
        /// <summary>
        /// Callback when we get the image.
        /// </summary>
        /// <param name="response"></param>
        public async void OnRequestComplete(object sender, ImageManager.ImageManagerResponseEventArgs response)
        {
            // Remove the event
            ImageManager.ImageManagerRequest request = (ImageManager.ImageManagerRequest)sender;
            request.OnRequestComplete -= OnRequestComplete;

            // Jump back to the UI thread
            await global::Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                if (!response.Success)
                {
                    m_base.FireOnFallbackToBrowser();
                    return;
                }

                lock (this)
                {
                    if (m_base.IsDestoryed)
                    {
                        // Get out of here if we should be destroyed.
                        return;
                    }

                    // Grab the source, we need this to make the image
                    m_imageSourceStream = response.ImageStream;

                    // Add the image to the UI
                    m_image = new Image();

                    // We don't want to wait on this.
#pragma warning disable CS4014
                    // Set the image.
                    ReloadImage(false);
#pragma warning restore CS4014

                    // Set the image into the UI.
                    ui_scrollViewer.Content = m_image;

                    // Setup the save image tap
                    m_image.RightTapped += ContentRoot_RightTapped;
                    m_image.Holding     += ContentRoot_Holding;
                    m_image.Width        = ui_scrollViewer.ViewportWidth;
                    m_image.Height       = ui_scrollViewer.ViewportHeight;
                }
            });
        }
        /// <summary>
        /// Callback when we get the image.
        /// </summary>
        /// <param name="response"></param>
        public async void OnRequestComplete(object sender, ImageManager.ImageManagerResponseEventArgs response)
        {
            // Remove the event
            ImageManager.ImageManagerRequest request = (ImageManager.ImageManagerRequest)sender;
            request.OnRequestComplete -= OnRequestComplete;

            // Jump back to the UI thread
            await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                if (!response.Success)
                {
                    App.BaconMan.TelemetryMan.ReportUnExpectedEvent(this, "BasicImageControlNoImageUrl");
                    m_host.ShowError();
                    return;
                }

                lock (m_host)
                {
                    if (m_isDestoryed)
                    {
                        // Get out of here if we should be destroyed.
                        return;
                    }

                    // Create a bitmap and set the source
                    BitmapImage bitImage = new BitmapImage();
                    bitImage.SetSource(response.ImageStream);

                    // Add the image to the UI
                    m_image        = new Image();
                    m_image.Source = bitImage;
                    ui_contentRoot.Children.Add(m_image);

                    // Setup the save image tap
                    m_image.RightTapped += ContentRoot_RightTapped;
                    m_image.Holding     += ContentRoot_Holding;

                    // Hide the loading screen
                    m_host.HideLoading();

                    // Show the image
                    ui_storyContentRoot.Begin();
                }
            });
        }
        /// <summary>
        /// Called when we should show content
        /// </summary>
        /// <param name="post"></param>
        public void OnPrepareContent(Post post)
        {
            // Set our flag
            m_isDestoryed = false;

            // First show loading
            m_host.ShowLoading();

            // Hide the content root
            ui_contentRoot.Opacity = 0;

            // Grab the post URL
            m_postUrl = post.Url;

            // Do the rest of the work on a background thread.
            Task.Run(async() =>
            {
                // Get the image Url
                string imageUrl = ImageManager.GetImageUrl(post.Url);

                if (String.IsNullOrWhiteSpace(imageUrl))
                {
                    // This is bad, we should be able to get the url.
                    App.BaconMan.TelemetryMan.ReportUnExpectedEvent(this, "BasicImageControlNoImageUrl");

                    // Jump back to the UI thread
                    await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        m_host.ShowError();
                    });

                    return;
                }

                // Fire off a request for the image.
                ImageManager.ImageManagerRequest request = new ImageManager.ImageManagerRequest()
                {
                    ImageId = post.Id,
                    Url     = imageUrl
                };
                request.OnRequestComplete += OnRequestComplete;
                App.BaconMan.ImageMan.QueueImageRequest(request);
            });
        }
        public async void OnRequestComplete(object sender, ImageManager.ImageManagerResponseEventArgs response)
        {
            // Remove the event
            ImageManager.ImageManagerRequest request = (ImageManager.ImageManagerRequest)sender;
            request.OnRequestComplete -= OnRequestComplete;

            // Make sure we were successful.
            if (response.Success)
            {
                // Try to find the post
                Post owningPost = null;

                // Lock the list
                lock (m_postsLists)
                {
                    foreach (Post post in m_postsLists)
                    {
                        if (post.Id.Equals(response.Request.ImageId))
                        {
                            owningPost = post;
                            break;
                        }
                    }
                }

                // If we didn't find it just return
                if (owningPost == null)
                {
                    return;
                }

                // Dispatch to the UI thread
                await global::Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    // Create a bitmap and set the source
                    owningPost.Image = new BitmapImage();
                    owningPost.Image.SetSource(response.ImageStream);

                    // Set the image visible
                    owningPost.ImageVisibility = Visibility.Visible;
                });
            }
        }
        /// <summary>
        /// Fired when we should load the content.
        /// </summary>
        /// <param name="source"></param>
        public async void OnPrepareContent()
        {
            //Run our work on a background thread.
            await Task.Run(() =>
            {
                // Get the image Url
                string imageUrl = ImageManager.GetImageUrl(m_base.Source.Url);

                // Make sure we got it.
                if (String.IsNullOrWhiteSpace(imageUrl))
                {
                    // This is bad, we should be able to get the url.
                    // Jump back to the UI thread
                    m_base.FireOnFallbackToBrowser();
                    return;
                }

                // Make sure we aren't destroyed.
                if (m_base.IsDestoryed)
                {
                    return;
                }

                // Fire off a request for the image.
                ImageManager.ImageManagerRequest request = new ImageManager.ImageManagerRequest()
                {
                    ImageId = m_base.Source.Id,
                    Url     = imageUrl
                };
                request.OnRequestComplete += OnRequestComplete;
                App.BaconMan.ImageMan.QueueImageRequest(request);
            });

            votesText.Text     = m_base.Source.post.Score.ToString();
            authorText.Text    = m_base.Source.post.Author;
            subredditText.Text = m_base.Source.post.Subreddit;
            titleText.Text     = m_base.Source.post.Title;
            commentsText.Text  = m_base.Source.post.NumComments.ToString() + " comments";

            m_context = m_base.Source.context;
        }
        /// <summary>
        /// Sets the posts to the UI.
        /// </summary>
        /// <param name="startingPos"></param>
        /// <param name="newPosts"></param>
        private async void SetPosts(int startingPos, List <Post> newPosts, bool isFreshUpdate)
        {
            // Dispatch to the UI thread
            await global::Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                // Setup the insert
                int insertIndex = startingPos;

                // Lock the list
                lock (m_postsLists)
                {
                    // Set up the objects for the UI
                    foreach (Post post in newPosts)
                    {
                        // Check if we are adding or inserting.
                        bool isReplace = insertIndex < m_postsLists.Count;

                        // If this is a replace and the urls are the same just set the image
                        if (isReplace && post.Url == m_postsLists[insertIndex].Url)
                        {
                            post.Image           = m_postsLists[insertIndex].Image;
                            post.ImageVisibility = m_postsLists[insertIndex].ImageVisibility;
                        }
                        else
                        {
                            // Request the image if there is one
                            if (ImageManager.IsThumbnailImage(post.Thumbnail))
                            {
                                ImageManager.ImageManagerRequest request = new ImageManager.ImageManagerRequest()
                                {
                                    Url     = post.Thumbnail,
                                    ImageId = post.Id
                                };
                                request.OnRequestComplete += OnRequestComplete;
                                App.BaconMan.ImageMan.QueueImageRequest(request);
                            }
                        }

                        if (isReplace)
                        {
                            if (m_postsLists[insertIndex].Id.Equals(post.Id))
                            {
                                // If the post is the same, just update the UI vars.
                                // If we replace the entire post the UI freaks out.
                                m_postsLists[insertIndex].Score               = post.Score;
                                m_postsLists[insertIndex].TitleTextColor      = post.TitleTextColor;
                                m_postsLists[insertIndex].Title               = post.Title;
                                m_postsLists[insertIndex].Likes               = post.Likes;
                                m_postsLists[insertIndex].SubTextLine1        = post.SubTextLine1;
                                m_postsLists[insertIndex].NewCommentText      = post.NewCommentText;
                                m_postsLists[insertIndex].SubTextLine2PartOne = post.SubTextLine2PartOne;
                                m_postsLists[insertIndex].SubTextLine2PartTwo = post.SubTextLine2PartTwo;
                            }
                            else
                            {
                                // Replace the current item
                                m_postsLists[insertIndex] = post;
                            }
                        }
                        else
                        {
                            // Add it to the end
                            m_postsLists.Add(post);
                        }
                        insertIndex++;
                    }

                    // If it was a fresh update, remove anything past the last story sent.
                    while (isFreshUpdate && m_postsLists.Count > newPosts.Count)
                    {
                        m_postsLists.RemoveAt(m_postsLists.Count - 1);
                    }
                }
            });
        }
        /// <summary>
        /// Fired when an image request is done.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="response"></param>
        public async void OnRequestComplete(object sender, ImageManager.ImageManagerResponseEventArgs response)
        {
            // Remove event listener
            ImageManager.ImageManagerRequest request = (ImageManager.ImageManagerRequest)sender;
            request.OnRequestComplete -= OnRequestComplete;

            UpdateTypes type = (UpdateTypes)response.Request.Context;

            // Make sure we were successfully.
            if (response.Success)
            {
                try
                {
                    // Get the target size
                    Size targetImageSize = LastKnownScreenResoultion;
                    if (type == UpdateTypes.Band)
                    {
                        if (m_baconMan.BackgroundMan.BandMan.BandVersion == BandVersions.V1)
                        {
                            targetImageSize = new Size(310, 102);
                        }
                        else
                        {
                            targetImageSize = new Size(310, 128);
                        }
                    }

                    // Resize the image to fit nicely
                    InMemoryRandomAccessStream image = await ResizeImage(response.ImageStream, targetImageSize);

                    // Write the file
                    await WriteImageToFile(image, type);
                }
                catch (Exception e)
                {
                    m_baconMan.MessageMan.DebugDia("Failed to write background image", e);
                    m_baconMan.TelemetryMan.ReportUnExpectedEvent(this, "Failed to write background image", e);
                }
            }

            // Indicate that this image is done.
            bool isDone = false;

            lock (m_getImageLock)
            {
                if (type == UpdateTypes.LockScreen)
                {
                    m_lockScreenDoneCount++;
                    isDone = m_lockScreenDoneCount >= m_lockScreenRequestCount;
                }
                else if (type == UpdateTypes.Band)
                {
                    m_bandDoneCount++;
                    isDone = m_bandDoneCount >= m_bandRequestCount;
                }
                else
                {
                    m_desktopDoneCount++;
                    isDone = m_desktopDoneCount >= m_desktopRequestCount;
                }
            }

            // if we are done done then tell the images to rotate and clean up.
            if (isDone)
            {
                // Set this high so we roll over.
                if (type == UpdateTypes.LockScreen)
                {
                    CurrentLockScreenRotationIndex = 99;
                }
                else if (type == UpdateTypes.Band)
                {
                    CurrentBandRotationIndex = 99;
                }
                else
                {
                    CurrentDesktopRotationIndex = 99;
                }

                // Do the rotate
                await DoImageRotation(type);

                // If this is a lock screen update this might also be a desktop update. This happens when the lock screen and desktop
                // share the same subreddit, they share the same images.
                if (type == UpdateTypes.LockScreen && IsDeskopEnabled && LockScreenSubredditName.Equals(DesktopSubredditName))
                {
                    // Off set the two so they don't show the same image
                    CurrentDesktopRotationIndex = 1;

                    // We also need to update the desktop.
                    await DoImageRotation(UpdateTypes.Desktop);
                }

                // We are done, set the last update time
                LastFullUpdate = DateTime.Now;

                // And kill the deferral
                ReleaseDeferral(type);

                // And set us to stopped.
                UnSetIsRunningIfDone();
            }
        }
        /// <summary>
        /// Given a list of post this gets the images and puts them into file cache.
        /// </summary>
        /// <param name="posts"></param>
        /// <param name="isLockScreen"></param>
        /// <returns></returns>
        private async void GetImagesFromPosts(List <Post> posts, UpdateTypes type)
        {
            // First, remove all of the existing images
            try
            {
                await DeleteAllCacheImages(type);
            }
            catch (Exception e)
            {
                m_baconMan.TelemetryMan.ReportUnExpectedEvent(this, "FailedToDeleteCacheImages", e);
            }

            // Setup the vars
            if (type == UpdateTypes.LockScreen)
            {
                m_lockScreenRequestCount = 0;
                m_lockScreenDoneCount    = 0;
            }
            else if (type == UpdateTypes.Band)
            {
                m_bandRequestCount = 0;
                m_bandDoneCount    = 0;
            }
            else
            {
                m_desktopRequestCount = 0;
                m_desktopDoneCount    = 0;
            }

            // Figure out all of the images we need to request.
            List <Tuple <string, string> > imageRequestList = new List <Tuple <string, string> >();

            foreach (Post post in posts)
            {
                string imageUrl = ImageManager.GetImageUrl(post.Url);
                if (!String.IsNullOrWhiteSpace(imageUrl))
                {
                    imageRequestList.Add(new Tuple <string, string>(imageUrl, post.Id));
                }

                if (imageRequestList.Count > c_maxImageCacheCount)
                {
                    break;
                }
            }

            // Now set our request counts before we start requesting. We must do this to ensure
            // the numbers are correct when the request come back.
            if (type == UpdateTypes.LockScreen)
            {
                m_lockScreenRequestCount = imageRequestList.Count;
            }
            else if (type == UpdateTypes.Band)
            {
                m_bandRequestCount = imageRequestList.Count;
            }
            else
            {
                m_desktopRequestCount = imageRequestList.Count;
            }

            // Now make all of the request.
            foreach (Tuple <string, string> request in imageRequestList)
            {
                // Make the request
                ImageManager.ImageManagerRequest imageRequst = new ImageManager.ImageManagerRequest()
                {
                    Url     = request.Item1,
                    ImageId = request.Item2,
                    Context = type
                };
                imageRequst.OnRequestComplete += OnRequestComplete;
                m_baconMan.ImageMan.QueueImageRequest(imageRequst);
            }

            // If we have nothing to request this is the end of the line for this type.
            if (imageRequestList.Count == 0)
            {
                // And kill the deferral
                ReleaseDeferral(type);

                // And set us to stopped.
                UnSetIsRunningIfDone();
            }
        }
        /// <summary>
        /// THREAD BLOCKING Given a list of post this gets the images and puts them into file cache.
        /// </summary>
        /// <param name="posts"></param>
        /// <param name="isLockScreen"></param>
        /// <returns></returns>
        private bool GetImagesFromPosts(List<Post> posts, bool isLockScreen)
        {
            // First, remove all of the existing images
            using (AutoResetEvent aEvent = new AutoResetEvent(false))
            {
                Task.Run(async () => { await DeleteAllCacheImages(isLockScreen); aEvent.Set(); });
                aEvent.WaitOne();
            }

            // Reset the wait event
            m_autoReset.Reset();

            // Setup vars
            m_reqeustCount = 0;
            m_imageReturnCount = 0;
            m_imageDoneCount = 0;
            m_isCurrentImageRequestLockScreen = isLockScreen;

            // Make request for the images
            foreach (Post post in posts)
            {
                string imageUrl = ImageManager.GetImageUrl(post.Url);
                if (!String.IsNullOrWhiteSpace(imageUrl))
                {
                    // Make the request
                    ImageManager.ImageManagerRequest request = new ImageManager.ImageManagerRequest()
                    {
                        Callback = this,
                        Url = imageUrl,
                        ImageId = post.Id
                    };
                    m_baconMan.ImageMan.QueueImageRequest(request);
                    m_reqeustCount++;
                }

                if(m_reqeustCount > c_maxImageCacheCount)
                {
                    break;
                }
            }

            // Wait for all of the images to be downloaded and stored.
            m_autoReset.WaitOne(10000);

            // See if we got all of the requests, then we are successful.
            return m_imageDoneCount >= (c_maxImageCacheCount - 2);
        }
        /// <summary>
        /// Given a list of post this gets the images and puts them into file cache.
        /// </summary>
        /// <param name="posts"></param>
        /// <param name="isLockScreen"></param>
        /// <returns></returns>
        private async void GetImagesFromPosts(List<Post> posts, UpdateTypes type)
        {
            // First, remove all of the existing images
            try
            {
                await DeleteAllCacheImages(type);
            }
            catch(Exception e)
            {
                m_baconMan.TelemetryMan.ReportUnExpectedEvent(this, "FailedToDeleteCacheImages", e);
            }

            // Setup the vars
            if(type == UpdateTypes.LockScreen)
            {
                m_lockScreenRequestCount = 0;
                m_lockScreenDoneCount = 0;
            }
            else if(type == UpdateTypes.Band)
            {
                m_bandRequestCount = 0;
                m_bandDoneCount = 0;
            }
            else
            {
                m_desktopRequestCount = 0;
                m_desktopDoneCount = 0;
            }

            // Figure out all of the images we need to request.
            List<Tuple<string, string>> imageRequestList = new List<Tuple<string, string>>();
            foreach (Post post in posts)
            {
                string imageUrl = ImageManager.GetImageUrl(post.Url);
                if (!String.IsNullOrWhiteSpace(imageUrl))
                {
                    imageRequestList.Add(new Tuple<string, string>(imageUrl, post.Id));
                }

                if(imageRequestList.Count > c_maxImageCacheCount)
                {
                    break;
                }
            }

            // Now set our request counts before we start requesting. We must do this to ensure
            // the numbers are correct when the request come back.
            if(type == UpdateTypes.LockScreen)
            {
                m_lockScreenRequestCount = imageRequestList.Count;
            }
            else if(type == UpdateTypes.Band)
            {
                m_bandRequestCount = imageRequestList.Count;
            }
            else
            {
                m_desktopRequestCount = imageRequestList.Count;
            }

            // Now make all of the request.
            foreach(Tuple<string, string> request in imageRequestList)
            {
                // Make the request
                ImageManager.ImageManagerRequest imageRequst = new ImageManager.ImageManagerRequest()
                {
                    Url = request.Item1,
                    ImageId = request.Item2,
                    Context = type
                };
                imageRequst.OnRequestComplete += OnRequestComplete;
                m_baconMan.ImageMan.QueueImageRequest(imageRequst);
            }  

            // If we have nothing to request this is the end of the line for this type.
            if(imageRequestList.Count == 0)
            {
                // And kill the deferral
                ReleaseDeferral(type);

                // And set us to stopped.
                UnSetIsRunningIfDone();
            }
        }