/// <summary> /// Start ImageBooster thread /// </summary> public async Task StartImageBoosterAsync() { while (IsRunWorker) { if (QueuedList.Count > 0) { // pop out the first item var index = QueuedList[0]; var img = ImgList[index]; QueuedList.RemoveAt(0); if (!img.IsDone) { // start loading image file await img.LoadAsync( size : ImgSize, colorProfileName : ColorProfileName, isApplyColorProfileForAll : IsApplyColorProfileForAll, channel : Channels, useEmbeddedThumbnail : UseEmbeddedThumbnail ).ConfigureAwait(true); } } await Task.Delay(10).ConfigureAwait(true); } }
/// <summary> /// Start ImageBooster thread /// </summary> public async void StartImageBooster() { while (this.IsRunWorker) { if (this.QueuedList.Count > 0) { // pop out the first item var index = this.QueuedList[0]; var img = this.ImgList[index]; QueuedList.RemoveAt(0); if (!img.IsDone) { // start loading image file await img.LoadAsync( size : this.ImgSize, colorProfileName : this.ColorProfileName, isApplyColorProfileForAll : this.IsApplyColorProfileForAll, channel : this.Channels, useEmbeddedThumbnail : this.UseEmbeddedThumbnail ); } } await Task.Delay(10); } }
/// <summary> /// Clear all cached images and release resource of the list /// </summary> public void ClearCache() { // release the resources of the img list foreach (var item in ImgList) { item.Dispose(); } QueuedList.Clear(); }
public Demo() { renderGroup = new QueuedList<IRenderable>(); gameObjects = new QueuedList<IGameEntity>(); modelEntityFactory = new ModelEntityFactory(); Random = new Random(); ForceRegistry = new ForceRegistry(); }
public Demo( ContentManager contentManager, RenderContext renderContext, QueuedList<IRenderable> renderGroup, QueuedList<IGameEntity> gameObjects) : base() { content = contentManager; this.renderContext = renderContext; this.renderGroup = renderGroup; this.gameObjects = gameObjects; ForceRegistry = new ForceRegistry(); }
/// <summary> /// Update cached images /// </summary> public void UpdateCache() { // clear current queue list QueuedList.Clear(); var cachedIndexList = ImgList .Select((item, index) => new { ImgItem = item, Index = index }) .Where(item => item.ImgItem.IsDone) .Select(item => item.Index) .ToList(); // release the cachced images foreach (var index in cachedIndexList) { ImgList[index].Dispose(); } // add to queue list QueuedList.AddRange(cachedIndexList); }
/// <summary> /// Add index of the image to queue list /// </summary> /// <param name="index">Current index of image list</param> private void UpdateQueueList(int index) { // check valid index if (index < 0 || index >= ImgList.Count) { return; } var list = new HashSet <int> { index }; var maxCachedItems = (MaxQueue * 2) + 1; var iRight = index; var iLeft = index; // add index in the range in order: index -> right -> left -> ... for (var i = 0; list.Count < maxCachedItems && list.Count < ImgList.Count; i++) { // if i is even number if ((i & 1) == 0) { // add right item: [index + 1; ...; to] iRight++; if (iRight < ImgList.Count) { list.Add(iRight); } else { list.Add(iRight - ImgList.Count); } } // if i is odd number else { // add left item: [index - 1; ...; from] iLeft--; if (iLeft >= 0) { list.Add(iLeft); } else { list.Add(ImgList.Count + iLeft); } } } // release the resources foreach (var indexItem in FreeList) { if (!list.Contains(indexItem) && indexItem >= 0 && indexItem < ImgList.Count) { ImgList[indexItem].Dispose(); } } // update new index of free list FreeList.Clear(); FreeList.AddRange(list); // update queue list QueuedList.Clear(); QueuedList.AddRange(list); }