コード例 #1
0
 protected override void ShownOnScreen()
 {
     if (!(this._uri != null) || !this._uri.IsAbsoluteUri)
     {
         return;
     }
     VeryLowProfileImageLoader.SetPriority(this._uri.OriginalString, DateTime.Now.Ticks);
 }
コード例 #2
0
 public static bool HasImageInLRUCache(Uri uri)
 {
     if (uri == null)
     {
         return(false);
     }
     VeryLowProfileImageLoader.EnsureLRUCache();
     return(VeryLowProfileImageLoader._lruCache.Get(uri) != null);
 }
コード例 #3
0
 private static void AddToCache(Uri uri, Stream stream)
 {
     VeryLowProfileImageLoader.EnsureLRUCache();
     VeryLowProfileImageLoader._lruCache.Add(uri, (Stream)StreamUtils.ReadFully(stream), true);
     stream.Position = 0L;
     if (UriExtensions.ParseQueryString(uri).ContainsKey(VeryLowProfileImageLoader.REQUIRE_CACHING_KEY))
     {
         ImageCache.Current.TrySetImageForUri(uri.OriginalString, (Stream)StreamUtils.ReadFully(stream));
     }
     stream.Position = 0L;
 }
コード例 #4
0
 public static void SaveState()
 {
     lock (VeryLowProfileImageLoader._downloadedDictLock)
     {
         VeryLowProfileImageLoader.SerializedData local_2 = new VeryLowProfileImageLoader.SerializedData()
         {
             DownloadedUris = VeryLowProfileImageLoader._downloadedList.Skip <string>(Math.Max(0, VeryLowProfileImageLoader._downloadedList.Count <string>() - 1000)).Take <string>(1000).ToList <string>()
         };
         CacheManager.TrySerialize((IBinarySerializable)local_2, "VeryLowProfileImageLoaderData", false, CacheManager.DataType.CachedData);
         VeryLowProfileImageLoader.Log("VeryLowProfileImageLoader serialized uri count " + (object)local_2.DownloadedUris.Count);
     }
 }
コード例 #5
0
 public static void SaveState()
 {
     lock (VeryLowProfileImageLoader._downloadedDictLock)
     {
         VeryLowProfileImageLoader.SerializedData serializedData = new VeryLowProfileImageLoader.SerializedData()
         {
             DownloadedUris = (List <string>)Enumerable.ToList <string>(Enumerable.Take <string>(Enumerable.Skip <string>(VeryLowProfileImageLoader._downloadedList, Math.Max(0, Enumerable.Count <string>(VeryLowProfileImageLoader._downloadedList) - 1000)), 1000))
         };
         CacheManager.TrySerialize((IBinarySerializable)serializedData, "VeryLowProfileImageLoaderData", false, CacheManager.DataType.CachedData);
         VeryLowProfileImageLoader.Log("VeryLowProfileImageLoader serialized uri count " + serializedData.DownloadedUris.Count);
     }
 }
コード例 #6
0
 private static void AddPendingRequest(Image image, Uri uri, int currentAttempt)
 {
     if (VeryLowProfileImageLoader.GetCleanupSourceWhenNewUriPending(image))
     {
         image.Source = (null);
     }
     lock (VeryLowProfileImageLoader._syncBlock)
     {
         VeryLowProfileImageLoader._pendingRequests.Enqueue(new VeryLowProfileImageLoader.PendingRequest(image, uri, currentAttempt));
         Monitor.Pulse(VeryLowProfileImageLoader._syncBlock);
     }
 }
コード例 #7
0
 public static void RestoreState()
 {
     lock (VeryLowProfileImageLoader._downloadedDictLock)
     {
         VeryLowProfileImageLoader.SerializedData local_2 = new VeryLowProfileImageLoader.SerializedData();
         CacheManager.TryDeserialize((IBinarySerializable)local_2, "VeryLowProfileImageLoaderData", CacheManager.DataType.CachedData);
         VeryLowProfileImageLoader._downloadedList = local_2.DownloadedUris;
         foreach (string item_0 in VeryLowProfileImageLoader._downloadedList)
         {
             VeryLowProfileImageLoader._downloadedDictionary[item_0] = "";
         }
         VeryLowProfileImageLoader.Log("VeryLowProfileImageLoader deserialized uri count " + (object)local_2.DownloadedUris.Count);
     }
 }
コード例 #8
0
        public static Stream GetFromLRUCache(Uri uri)
        {
            VeryLowProfileImageLoader.EnsureLRUCache();
            Stream stream = VeryLowProfileImageLoader._lruCache.Get(uri);

            if (stream == null)
            {
                return(null);
            }
            MemoryStream memoryStream = StreamUtils.ReadFully(stream);

            stream.Position = 0L;
            return((Stream)memoryStream);
        }
コード例 #9
0
 public static void RestoreState()
 {
     lock (VeryLowProfileImageLoader._downloadedDictLock)
     {
         VeryLowProfileImageLoader.SerializedData serializedData = new VeryLowProfileImageLoader.SerializedData();
         CacheManager.TryDeserialize((IBinarySerializable)serializedData, "VeryLowProfileImageLoaderData", CacheManager.DataType.CachedData);
         VeryLowProfileImageLoader._downloadedList = serializedData.DownloadedUris;
         foreach (string downloaded in VeryLowProfileImageLoader._downloadedList)
         {
             VeryLowProfileImageLoader._downloadedDictionary[downloaded] = "";
         }
         VeryLowProfileImageLoader.Log("VeryLowProfileImageLoader deserialized uri count " + serializedData.DownloadedUris.Count);
     }
 }
コード例 #10
0
 private static int RemoveStaleAndGetCount()
 {
     lock (VeryLowProfileImageLoader._lockDict)
     {
         DateTime now = DateTime.Now;
         List <VeryLowProfileImageLoader.PendingRequest> temp_13 = VeryLowProfileImageLoader._requestsInProcess.Values.Where <VeryLowProfileImageLoader.PendingRequest>((Func <VeryLowProfileImageLoader.PendingRequest, bool>)(r => (now - r.DownloadStaredTimestamp).TotalMilliseconds > (double)VeryLowProfileImageLoader.STALE_THRESHOLD)).ToList <VeryLowProfileImageLoader.PendingRequest>();
         int local_3 = 0;
         foreach (VeryLowProfileImageLoader.PendingRequest item_0 in temp_13)
         {
             VeryLowProfileImageLoader.RemoveRequestInProgress(item_0.UniqueId);
             VeryLowProfileImageLoader.Log("REMOVED STALE " + item_0.Uri.OriginalString);
             ++local_3;
         }
         return(VeryLowProfileImageLoader._requestsInProcess.Count);
     }
 }
コード例 #11
0
 private static int RemoveStaleAndGetCount()
 {
     lock (VeryLowProfileImageLoader._lockDict)
     {
         DateTime now = DateTime.Now;
         List <VeryLowProfileImageLoader.PendingRequest> list = Enumerable.ToList <VeryLowProfileImageLoader.PendingRequest>(Enumerable.Where <VeryLowProfileImageLoader.PendingRequest>(VeryLowProfileImageLoader._requestsInProcess.Values, (Func <VeryLowProfileImageLoader.PendingRequest, bool>)(r => (now - r.DownloadStaredTimestamp).TotalMilliseconds > (double)VeryLowProfileImageLoader.STALE_THRESHOLD)));
         int num = 0;
         foreach (VeryLowProfileImageLoader.PendingRequest pendingRequest in (List <VeryLowProfileImageLoader.PendingRequest>)list)
         {
             VeryLowProfileImageLoader.RemoveRequestInProgress(pendingRequest.UniqueId);
             VeryLowProfileImageLoader.Log("REMOVED STALE " + pendingRequest.Uri.OriginalString);
             ++num;
         }
         return(VeryLowProfileImageLoader._requestsInProcess.Count);
     }
 }
コード例 #12
0
        // UPDATE: 4.8.0
        protected override void LoadFullyNonVirtualizableItems()
        {
            Image image = this.Children.FirstOrDefault <FrameworkElement>((Func <FrameworkElement, bool>)(c => c is Image)) as Image;

            if (this._uri != null)
            {
                VeryLowProfileImageLoader.SetUriSource(image, this._uri);
            }
            else
            {
                if (this._stream == null)
                {
                    return;
                }
                ImageLoader.SetStreamSource(image, this._stream);
            }
        }
コード例 #13
0
        private static void OnUriSourceChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            Image image = (Image)o;
            // ISSUE: explicit reference operation
            Uri newValue = (Uri)e.NewValue;
            int num1     = newValue == null ? 1 : 0;

            VeryLowProfileImageLoader._hashToUriDict[(image).GetHashCode()] = newValue;
            if (newValue == null)
            {
                BitmapImage source = image.Source as BitmapImage;
                image.Source = (null);
                if (source != null)
                {
                    VeryLowProfileImageLoader.DisposeImage(source);
                }
                VeryLowProfileImageLoader.Log("OnUriSourceChanged uri = NULL");
            }
            else
            {
                VeryLowProfileImageLoader.Log(string.Format("OnUriSourceChanged uri = {0}", newValue));
                Stream stream = VeryLowProfileImageLoader.GetFromLRUCache(newValue) ?? ImageCache.Current.GetCachedImageStream(newValue.OriginalString);
                if (stream != null)
                {
                    BitmapImage sizedBitmap = VeryLowProfileImageLoader.CreateSizedBitmap((FrameworkElement)image, newValue, VeryLowProfileImageLoader.GetUseBackgroundCreation(image));
                    ((BitmapSource)sizedBitmap).SetSource(stream);
                    image.Source = ((ImageSource)sizedBitmap);
                }
                else if (!newValue.IsAbsoluteUri || !VeryLowProfileImageLoader.IsEnabled || DesignerProperties.IsInDesignTool)
                {
                    BitmapImage bitmapImage1 = new BitmapImage();
                    int         num2         = 18;
                    bitmapImage1.CreateOptions = ((BitmapCreateOptions)num2);
                    Uri uri = newValue;
                    bitmapImage1.UriSource = uri;
                    BitmapImage bitmapImage2 = bitmapImage1;
                    image.Source = ((ImageSource)bitmapImage2);
                }
                else
                {
                    VeryLowProfileImageLoader.AddPendingRequest(image, newValue, 1);
                }
            }
        }
コード例 #14
0
        private static void OnUriSourceChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            Image image = (Image)o;
            Uri   uri   = (Uri)e.NewValue;
            int   num   = uri == null ? 1 : 0;

            VeryLowProfileImageLoader._hashToUriDict[image.GetHashCode()] = uri;
            if (uri == null)
            {
                BitmapImage img = image.Source as BitmapImage;
                image.Source = null;
                if (img != null)
                {
                    VeryLowProfileImageLoader.DisposeImage(img);
                }
                VeryLowProfileImageLoader.Log("OnUriSourceChanged uri = NULL");
            }
            else
            {
                VeryLowProfileImageLoader.Log(string.Format("OnUriSourceChanged uri = {0}", (object)uri));
                Stream streamSource = VeryLowProfileImageLoader.GetFromLRUCache(uri) ?? ImageCache.Current.GetCachedImageStream(uri.OriginalString);
                if (streamSource != null)
                {
                    BitmapImage sizedBitmap = VeryLowProfileImageLoader.CreateSizedBitmap((FrameworkElement)image, uri, VeryLowProfileImageLoader.GetUseBackgroundCreation(image));
                    sizedBitmap.SetSource(streamSource);
                    image.Source = (ImageSource)sizedBitmap;
                }
                else if (!uri.IsAbsoluteUri || !VeryLowProfileImageLoader.IsEnabled || DesignerProperties.IsInDesignTool)
                {
                    BitmapImage bitmapImage = new BitmapImage()
                    {
                        CreateOptions = BitmapCreateOptions.DelayCreation | BitmapCreateOptions.BackgroundCreation,
                        UriSource     = uri
                    };
                    image.Source = (ImageSource)bitmapImage;
                }
                else
                {
                    VeryLowProfileImageLoader.AddPendingRequest(image, uri, 1);
                }
            }
        }
コード例 #15
0
ファイル: ImageLoader.cs プロジェクト: Makzz90/VKClient_re
        private static void HandleUriChangeLowProfile(Image image, string uriStr)
        {
            Uri uri = uriStr.ConvertToUri();

            VeryLowProfileImageLoader.SetUriSource(image, uri);
        }
コード例 #16
0
        private static void WorkerThreadProc(object unused)
        {
            Random rand = new Random();
            List <VeryLowProfileImageLoader.PendingRequest> list = new List <VeryLowProfileImageLoader.PendingRequest>();
            Queue <IAsyncResult> queue = new Queue <IAsyncResult>();

            VeryLowProfileImageLoader.RestoreState();
            while (!VeryLowProfileImageLoader._exiting)
            {
                object syncBlock = VeryLowProfileImageLoader._syncBlock;
                lock (syncBlock)
                {
                    int num = VeryLowProfileImageLoader.RemoveStaleAndGetCount();
                    if ((VeryLowProfileImageLoader._pendingRequests.Count == 0 && VeryLowProfileImageLoader._pendingResponses.Count == 0 && list.Count == 0 && queue.Count == 0) || num >= VeryLowProfileImageLoader.MaxSimultaneousLoads)
                    {
                        Monitor.Wait(VeryLowProfileImageLoader._syncBlock, 300);
                        if (VeryLowProfileImageLoader._exiting)
                        {
                            break;
                        }
                    }
                    while (0 < VeryLowProfileImageLoader._pendingRequests.Count)
                    {
                        VeryLowProfileImageLoader.PendingRequest pendingRequest = VeryLowProfileImageLoader._pendingRequests.Dequeue();
                        for (int i = 0; i < list.Count; i++)
                        {
                            if (list[i].Image == pendingRequest.Image)
                            {
                                list[i]        = pendingRequest;
                                pendingRequest = null;
                                break;
                            }
                        }
                        if (pendingRequest != null)
                        {
                            list.Add(pendingRequest);
                        }
                    }
                    while (0 < VeryLowProfileImageLoader._pendingResponses.Count)
                    {
                        queue.Enqueue(VeryLowProfileImageLoader._pendingResponses.Dequeue());
                    }
                }
                Queue <VeryLowProfileImageLoader.PendingCompletion> pendingCompletions = new Queue <VeryLowProfileImageLoader.PendingCompletion>();
                int num2 = 0;
                List <VeryLowProfileImageLoader.PendingRequest> list2 = new List <VeryLowProfileImageLoader.PendingRequest>();
                for (int j = 0; j < list.Count; j++)
                {
                    VeryLowProfileImageLoader.PendingRequest pendingRequest2 = list[j];
                    if (VeryLowProfileImageLoader._hashToUriDict[pendingRequest2.Image.GetHashCode()] != pendingRequest2.Uri)
                    {
                        list2.Add(pendingRequest2);
                    }
                }
                using (List <VeryLowProfileImageLoader.PendingRequest> .Enumerator enumerator = list2.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        VeryLowProfileImageLoader.PendingRequest current = enumerator.Current;
                        list.Remove(current);
                    }
                }
                if (list2.Count > 0)
                {
                    VeryLowProfileImageLoader.Log("Discarded " + list2.Count);
                }
                int num3 = VeryLowProfileImageLoader.RemoveStaleAndGetCount();
                IEnumerable <VeryLowProfileImageLoader.PendingRequest> arg_1F8_0 = list;
                Func <VeryLowProfileImageLoader.PendingRequest, bool>  arg_1F8_1 = new Func <VeryLowProfileImageLoader.PendingRequest, bool>((pr) => { return(VeryLowProfileImageLoader.HaveInDownloadedDict(pr)); });

                using (IEnumerator <VeryLowProfileImageLoader.PendingRequest> enumerator2 = Enumerable.Take <VeryLowProfileImageLoader.PendingRequest>(Enumerable.ToList <VeryLowProfileImageLoader.PendingRequest>(Enumerable.Where <VeryLowProfileImageLoader.PendingRequest>(arg_1F8_0, arg_1F8_1)), 3).GetEnumerator())
                {
                    while (enumerator2.MoveNext())
                    {
                        VeryLowProfileImageLoader.PendingRequest current2 = enumerator2.Current;
                        HttpWebRequest httpWebRequest = WebRequest.CreateHttp(current2.Uri);
                        httpWebRequest.AllowReadStreamBuffering = (true);
                        current2.DownloadStaredTimestamp        = DateTime.Now;
                        httpWebRequest.BeginGetResponse(new AsyncCallback(VeryLowProfileImageLoader.HandleGetResponseResult), new VeryLowProfileImageLoader.ResponseState(httpWebRequest, current2.Image, current2.Uri, current2.DownloadStaredTimestamp, current2.UniqueId, current2.CurrentAttempt));
                        list.Remove(current2);
                        VeryLowProfileImageLoader.Log("Processed Already downloaded " + current2.Uri);
                    }
                    goto IL_3DA;
                }
                //goto IL_2B9;
IL_3DA:
                if (num3 >= VeryLowProfileImageLoader.MaxSimultaneousLoads || list.Count <= 0)
                {
                    if (list.Count > 0)
                    {
                        syncBlock = VeryLowProfileImageLoader._syncBlock;
                        lock (syncBlock)
                        {
                            using (List <VeryLowProfileImageLoader.PendingRequest> .Enumerator enumerator = list.GetEnumerator())
                            {
                                while (enumerator.MoveNext())
                                {
                                    VeryLowProfileImageLoader.PendingRequest current3 = enumerator.Current;
                                    VeryLowProfileImageLoader._pendingRequests.Enqueue(current3);
                                }
                            }
                        }
                    }
                    int num4 = 0;
                    while (0 < queue.Count && num4 < 5)
                    {
                        IAsyncResult asyncResult = queue.Dequeue();
                        VeryLowProfileImageLoader.ResponseState responseState = (VeryLowProfileImageLoader.ResponseState)asyncResult.AsyncState;
                        try
                        {
                            WebResponse webResponse = responseState.WebRequest.EndGetResponse(asyncResult);
                            pendingCompletions.Enqueue(new VeryLowProfileImageLoader.PendingCompletion(responseState.Image, responseState.Uri, webResponse.GetResponseStream(), responseState.Timestamp, responseState.RequestId));
                        }
                        catch (WebException e)
                        {
                            Logger.Instance.Error(string.Format("LowProfileImageLoader exception when fetching {0}", responseState.Uri.OriginalString), e);
                            if (responseState.CurrentAttempt <= 3)
                            {
                                Execute.ExecuteOnUIThread(delegate
                                {
                                    VeryLowProfileImageLoader.AddPendingRequest(responseState.Image, responseState.Uri, responseState.CurrentAttempt + 1);
                                });
                            }
                        }
                        Thread.Sleep(1);
                        num4++;
                    }
                    if (0 < pendingCompletions.Count)
                    {
                        Deployment.Current.Dispatcher.BeginInvoke(delegate
                        {
                            List <VeryLowProfileImageLoader.PendingCompletion> list3 = new List <VeryLowProfileImageLoader.PendingCompletion>();
                            while (0 < pendingCompletions.Count)
                            {
                                VeryLowProfileImageLoader.PendingCompletion pendingCompletion = pendingCompletions.Dequeue();
                                list3.Add(pendingCompletion);
                                VeryLowProfileImageLoader.AddToDownloadedDict(pendingCompletion.Uri);
                                VeryLowProfileImageLoader.AddToCache(pendingCompletion.Uri, pendingCompletion.Stream);
                                if (VeryLowProfileImageLoader.GetUriSource(pendingCompletion.Image) == pendingCompletion.Uri)
                                {
                                    BitmapImage bitmapImage = VeryLowProfileImageLoader.CreateSizedBitmap(pendingCompletion.Image, pendingCompletion.Uri, VeryLowProfileImageLoader.GetUseBackgroundCreation(pendingCompletion.Image));
                                    try
                                    {
                                        bitmapImage.SetSource(pendingCompletion.Stream);
                                    }
                                    catch (Exception e2)
                                    {
                                        Logger.Instance.Error("Error of reading image", e2);
                                    }
                                    pendingCompletion.Image.Source = (bitmapImage);
                                    DateTime arg_B8_0 = DateTime.Now;
                                    VeryLowProfileImageLoader._totalDownloadCount++;
                                    double totalMilliseconds = (arg_B8_0 - pendingCompletion.Timestamp).TotalMilliseconds;
                                    VeryLowProfileImageLoader.Log(string.Format("Downloaded image {0} in {1} ms. Totally downloaded = {2}", pendingCompletion.Uri.OriginalString, totalMilliseconds, VeryLowProfileImageLoader._totalDownloadCount));
                                    if (VeryLowProfileImageLoader._enableLog)
                                    {
                                        VeryLowProfileImageLoader._statistics.Add(totalMilliseconds);
                                        if (VeryLowProfileImageLoader._statistics.Count % 30 == 0 && VeryLowProfileImageLoader._statistics.Count > 0)
                                        {
                                            double num5 = Enumerable.Max(VeryLowProfileImageLoader._statistics);
                                            double num6 = Enumerable.Sum(VeryLowProfileImageLoader._statistics) / (double)VeryLowProfileImageLoader._statistics.Count;
                                            VeryLowProfileImageLoader.Log(string.Format("Statistics downloading: average {0}, max = {1}", num6, num5));
                                        }
                                    }
                                }
                                pendingCompletion.Stream.Dispose();
                            }
                            try
                            {
                                using (List <VeryLowProfileImageLoader.PendingCompletion> .Enumerator enumerator3 = list3.GetEnumerator())
                                {
                                    while (enumerator3.MoveNext())
                                    {
                                        VeryLowProfileImageLoader.RemoveRequestInProgress(enumerator3.Current.RequestId);
                                    }
                                }
                            }
                            catch (Exception)
                            {
                            }
                        });
                        continue;
                    }
                    continue;
                }
//		IL_2B9:
                if (num2 >= VeryLowProfileImageLoader.MaxSimultaneousLoads)
                {
                    VeryLowProfileImageLoader.Log("!!!!! noOfCycles=" + num2);
                }
                int count = list.Count;
                int indexOfElementWithMaxPriority = VeryLowProfileImageLoader.GetIndexOfElementWithMaxPriority(list, rand);
                VeryLowProfileImageLoader.PendingRequest pendingRequest3 = list[indexOfElementWithMaxPriority];
                list[indexOfElementWithMaxPriority] = list[count - 1];
                list.RemoveAt(count - 1);
                HttpWebRequest httpWebRequest2 = WebRequest.CreateHttp(pendingRequest3.Uri);
                httpWebRequest2.AllowReadStreamBuffering = (true);
                pendingRequest3.DownloadStaredTimestamp  = DateTime.Now;
                httpWebRequest2.BeginGetResponse(new AsyncCallback(VeryLowProfileImageLoader.HandleGetResponseResult), new VeryLowProfileImageLoader.ResponseState(httpWebRequest2, pendingRequest3.Image, pendingRequest3.Uri, pendingRequest3.DownloadStaredTimestamp, pendingRequest3.UniqueId, pendingRequest3.CurrentAttempt));
                VeryLowProfileImageLoader.AddRequestInProgress(pendingRequest3);
                num3++;
                VeryLowProfileImageLoader.Log(string.Concat(new object[]
                {
                    "Loading ",
                    pendingRequest3.Uri,
                    ";processing started in ",
                    (DateTime.Now - pendingRequest3.CreatedTimstamp).TotalMilliseconds,
                    " Currently loading ",
                    num3
                }));
                goto IL_3DA;
            }
        }
コード例 #17
0
 protected override void ReleaseResourcesOnUnload()
 {
     VeryLowProfileImageLoader.SetUriSource(this.Children.FirstOrDefault <FrameworkElement>((Func <FrameworkElement, bool>)(c => c is Image)) as Image, null);
 }
コード例 #18
0
 private static bool HaveInDownloadedDict(VeryLowProfileImageLoader.PendingRequest pr)
 {
     return(VeryLowProfileImageLoader.HaveInDownloadedDict(pr.Uri));
 }
コード例 #19
0
        private static void WorkerThreadProc(object unused)
        {
            Random rand = new Random();
            List <VeryLowProfileImageLoader.PendingRequest> pendingRequestList1 = new List <VeryLowProfileImageLoader.PendingRequest>();
            Queue <IAsyncResult> asyncResultQueue = new Queue <IAsyncResult>();

            VeryLowProfileImageLoader.RestoreState();
            while (!VeryLowProfileImageLoader._exiting)
            {
                lock (VeryLowProfileImageLoader._syncBlock)
                {
                    int local_9 = VeryLowProfileImageLoader.RemoveStaleAndGetCount();
                    if (VeryLowProfileImageLoader._pendingRequests.Count == 0 && VeryLowProfileImageLoader._pendingResponses.Count == 0 && (pendingRequestList1.Count == 0 && asyncResultQueue.Count == 0) || local_9 >= VeryLowProfileImageLoader.MaxSimultaneousLoads)
                    {
                        Monitor.Wait(VeryLowProfileImageLoader._syncBlock, 300);
                        if (VeryLowProfileImageLoader._exiting)
                        {
                            break;
                        }
                    }
                    while (0 < VeryLowProfileImageLoader._pendingRequests.Count)
                    {
                        VeryLowProfileImageLoader.PendingRequest local_10 = VeryLowProfileImageLoader._pendingRequests.Dequeue();
                        for (int local_11 = 0; local_11 < pendingRequestList1.Count; ++local_11)
                        {
                            if (pendingRequestList1[local_11].Image == local_10.Image)
                            {
                                pendingRequestList1[local_11] = local_10;
                                local_10 = null;
                                break;
                            }
                        }
                        if (local_10 != null)
                        {
                            pendingRequestList1.Add(local_10);
                        }
                    }
                    while (0 < VeryLowProfileImageLoader._pendingResponses.Count)
                    {
                        asyncResultQueue.Enqueue(VeryLowProfileImageLoader._pendingResponses.Dequeue());
                    }
                }
                Queue <VeryLowProfileImageLoader.PendingCompletion> pendingCompletions = new Queue <VeryLowProfileImageLoader.PendingCompletion>();
                int num1 = 0;
                List <VeryLowProfileImageLoader.PendingRequest> pendingRequestList2 = new List <VeryLowProfileImageLoader.PendingRequest>();
                for (int index = 0; index < pendingRequestList1.Count; ++index)
                {
                    VeryLowProfileImageLoader.PendingRequest pendingRequest = pendingRequestList1[index];
                    if (VeryLowProfileImageLoader._hashToUriDict[pendingRequest.Image.GetHashCode()] != pendingRequest.Uri)
                    {
                        pendingRequestList2.Add(pendingRequest);
                    }
                }
                foreach (VeryLowProfileImageLoader.PendingRequest pendingRequest in pendingRequestList2)
                {
                    pendingRequestList1.Remove(pendingRequest);
                }
                if (pendingRequestList2.Count > 0)
                {
                    VeryLowProfileImageLoader.Log("Discarded " + (object)pendingRequestList2.Count);
                }
                int count1 = VeryLowProfileImageLoader.RemoveStaleAndGetCount();
                foreach (VeryLowProfileImageLoader.PendingRequest pendingRequest in pendingRequestList1.Where <VeryLowProfileImageLoader.PendingRequest>((Func <VeryLowProfileImageLoader.PendingRequest, bool>)(pr => VeryLowProfileImageLoader.HaveInDownloadedDict(pr))).ToList <VeryLowProfileImageLoader.PendingRequest>().Take <VeryLowProfileImageLoader.PendingRequest>(3))
                {
                    HttpWebRequest http = WebRequest.CreateHttp(pendingRequest.Uri);
                    http.AllowReadStreamBuffering          = true;
                    pendingRequest.DownloadStaredTimestamp = DateTime.Now;
                    http.BeginGetResponse(new AsyncCallback(VeryLowProfileImageLoader.HandleGetResponseResult), (object)new VeryLowProfileImageLoader.ResponseState((WebRequest)http, pendingRequest.Image, pendingRequest.Uri, pendingRequest.DownloadStaredTimestamp, pendingRequest.UniqueId, pendingRequest.CurrentAttempt));
                    pendingRequestList1.Remove(pendingRequest);
                    VeryLowProfileImageLoader.Log("Processed Already downloaded " + (object)pendingRequest.Uri);
                }
                while (count1 < VeryLowProfileImageLoader.MaxSimultaneousLoads && pendingRequestList1.Count > 0)
                {
                    if (num1 >= VeryLowProfileImageLoader.MaxSimultaneousLoads)
                    {
                        VeryLowProfileImageLoader.Log("!!!!! noOfCycles=" + (object)num1);
                    }
                    int count2 = pendingRequestList1.Count;
                    int elementWithMaxPriority = VeryLowProfileImageLoader.GetIndexOfElementWithMaxPriority(pendingRequestList1, rand);
                    VeryLowProfileImageLoader.PendingRequest request = pendingRequestList1[elementWithMaxPriority];
                    pendingRequestList1[elementWithMaxPriority] = pendingRequestList1[count2 - 1];
                    pendingRequestList1.RemoveAt(count2 - 1);
                    HttpWebRequest http = WebRequest.CreateHttp(request.Uri);
                    http.AllowReadStreamBuffering   = true;
                    request.DownloadStaredTimestamp = DateTime.Now;
                    http.BeginGetResponse(new AsyncCallback(VeryLowProfileImageLoader.HandleGetResponseResult), (object)new VeryLowProfileImageLoader.ResponseState((WebRequest)http, request.Image, request.Uri, request.DownloadStaredTimestamp, request.UniqueId, request.CurrentAttempt));
                    VeryLowProfileImageLoader.AddRequestInProgress(request);
                    ++count1;
                    VeryLowProfileImageLoader.Log("Loading " + (object)request.Uri + ";processing started in " + (object)(DateTime.Now - request.CreatedTimstamp).TotalMilliseconds + " Currently loading " + (object)count1);
                }
                if (pendingRequestList1.Count > 0)
                {
                    lock (VeryLowProfileImageLoader._syncBlock)
                    {
                        foreach (VeryLowProfileImageLoader.PendingRequest item_1 in pendingRequestList1)
                        {
                            VeryLowProfileImageLoader._pendingRequests.Enqueue(item_1);
                        }
                    }
                }
                for (int index = 0; 0 < asyncResultQueue.Count && index < 5; ++index)
                {
                    IAsyncResult asyncResult = asyncResultQueue.Dequeue();
                    VeryLowProfileImageLoader.ResponseState responseState = (VeryLowProfileImageLoader.ResponseState)asyncResult.AsyncState;
                    try
                    {
                        WebResponse response = responseState.WebRequest.EndGetResponse(asyncResult);
                        pendingCompletions.Enqueue(new VeryLowProfileImageLoader.PendingCompletion(responseState.Image, responseState.Uri, response.GetResponseStream(), responseState.Timestamp, responseState.RequestId));
                    }
                    catch (WebException ex)
                    {
                        Logger.Instance.Error(string.Format("LowProfileImageLoader exception when fetching {0}", (object)responseState.Uri.OriginalString), (Exception)ex);
                        if (responseState.CurrentAttempt <= 3)
                        {
                            Execute.ExecuteOnUIThread((Action)(() => VeryLowProfileImageLoader.AddPendingRequest(responseState.Image, responseState.Uri, responseState.CurrentAttempt + 1)));
                        }
                    }
                    Thread.Sleep(1);
                }
                if (0 < pendingCompletions.Count)
                {
                    Deployment.Current.Dispatcher.BeginInvoke((Action)(() =>
                    {
                        List <VeryLowProfileImageLoader.PendingCompletion> pendingCompletionList = new List <VeryLowProfileImageLoader.PendingCompletion>();
                        while (0 < pendingCompletions.Count)
                        {
                            VeryLowProfileImageLoader.PendingCompletion pendingCompletion = pendingCompletions.Dequeue();
                            pendingCompletionList.Add(pendingCompletion);
                            VeryLowProfileImageLoader.AddToDownloadedDict(pendingCompletion.Uri);
                            VeryLowProfileImageLoader.AddToCache(pendingCompletion.Uri, pendingCompletion.Stream);
                            if (VeryLowProfileImageLoader.GetUriSource(pendingCompletion.Image) == pendingCompletion.Uri)
                            {
                                BitmapImage sizedBitmap = VeryLowProfileImageLoader.CreateSizedBitmap((FrameworkElement)pendingCompletion.Image, pendingCompletion.Uri, VeryLowProfileImageLoader.GetUseBackgroundCreation(pendingCompletion.Image));
                                try
                                {
                                    sizedBitmap.SetSource(pendingCompletion.Stream);
                                }
                                catch (Exception ex)
                                {
                                    Logger.Instance.Error("Error of reading image", ex);
                                }
                                pendingCompletion.Image.Source = (ImageSource)sizedBitmap;
                                DateTime now = DateTime.Now;
                                ++VeryLowProfileImageLoader._totalDownloadCount;
                                DateTime timestamp = pendingCompletion.Timestamp;
                                double totalMilliseconds = (now - timestamp).TotalMilliseconds;
                                VeryLowProfileImageLoader.Log(string.Format("Downloaded image {0} in {1} ms. Totally downloaded = {2}", (object)pendingCompletion.Uri.OriginalString, (object)totalMilliseconds, (object)VeryLowProfileImageLoader._totalDownloadCount));
                                if (VeryLowProfileImageLoader._enableLog)
                                {
                                    VeryLowProfileImageLoader._statistics.Add(totalMilliseconds);
                                    if (VeryLowProfileImageLoader._statistics.Count % 30 == 0 && VeryLowProfileImageLoader._statistics.Count > 0)
                                    {
                                        double num = VeryLowProfileImageLoader._statistics.Max();
                                        VeryLowProfileImageLoader.Log(string.Format("Statistics downloading: average {0}, max = {1}", (object)(VeryLowProfileImageLoader._statistics.Sum() / (double)VeryLowProfileImageLoader._statistics.Count), (object)num));
                                    }
                                }
                            }
                            pendingCompletion.Stream.Dispose();
                        }
                        try
                        {
                            foreach (VeryLowProfileImageLoader.PendingCompletion pendingCompletion in pendingCompletionList)
                            {
                                VeryLowProfileImageLoader.RemoveRequestInProgress(pendingCompletion.RequestId);
                            }
                        }
                        catch
                        {
                        }
                    }));
                }
            }
        }