コード例 #1
0
        /// <summary>
        /// Schedules the image loading. If image is found in cache then it returns it, otherwise it loads it.
        /// </summary>
        /// <param name="task">Image loading task.</param>
        public async void LoadImage(IImageLoaderTask task)
        {
            if (task == null)
            {
                return;
            }

            if (task.IsCancelled)
            {
                task.Parameters.Dispose();                 // this will ensure we don't keep a reference due to callbacks
                return;
            }

            bool loadedFromCache = await task.PrepareAndTryLoadingFromCacheAsync().ConfigureAwait(false);

            if (loadedFromCache)
            {
                if (task.Parameters.OnFinish != null)
                {
                    task.Parameters.OnFinish(task);
                }

                task.Parameters.Dispose(); // this will ensure we don't keep a reference due to callbacks
                return;                    // image successfully loaded from cache
            }

            if (task.IsCancelled || _pauseWork)
            {
                task.Parameters.Dispose();                 // this will ensure we don't keep a reference due to callbacks
                return;
            }

            QueueAndGenerateImage(task);
        }
コード例 #2
0
        /// <summary>
        /// Schedules the image loading. If image is found in cache then it returns it, otherwise it loads it.
        /// </summary>
        /// <param name="task">Image loading task.</param>
        public void LoadImage(IImageLoaderTask task)
        {
            if (task == null)
            {
                return;
            }

                        #pragma warning disable 4014
            Task.Run(async() =>
            {
                if (task.Parameters.DelayInMs != null && task.Parameters.DelayInMs > 0)
                {
                    await Task.Delay(task.Parameters.DelayInMs.Value).ConfigureAwait(false);
                }

                if (task.IsCancelled)
                {
                    task.Parameters.Dispose();                     // this will ensure we don't keep a reference due to callbacks
                    return;
                }

                if (!task.Parameters.Preload)
                {
                    List <PendingTask> pendingTasksCopy;
                    lock (_pendingTasksLock)
                    {
                        pendingTasksCopy = _pendingTasks.ToList();
                    }
                    foreach (var pendingTask in pendingTasksCopy)
                    {
                        if (pendingTask.ImageLoadingTask != null && pendingTask.ImageLoadingTask.UsesSameNativeControl(task))
                        {
                            pendingTask.ImageLoadingTask.CancelIfNeeded();
                        }
                    }
                }

                bool loadedFromCache = await task.PrepareAndTryLoadingFromCacheAsync().ConfigureAwait(false);
                if (loadedFromCache)
                {
                    if (task.Parameters.OnFinish != null)
                    {
                        task.Parameters.OnFinish(task);
                    }

                    task.Dispose();
                    return;                     // image successfully loaded from cache
                }

                if (task.IsCancelled || _pauseWork)
                {
                    task.Parameters.Dispose();                     // this will ensure we don't keep a reference due to callbacks
                    return;
                }

                QueueAndGenerateImage(task);
            });
                        #pragma warning restore 4014
        }
コード例 #3
0
        /// <summary>
        /// Schedules the image loading. If image is found in cache then it returns it, otherwise it loads it.
        /// </summary>
        /// <param name="task">Image loading task.</param>
        public async void LoadImage(IImageLoaderTask task)
        {
            if (task == null)
            {
                return;
            }

            if (task.IsCancelled)
            {
                task.Parameters.Dispose();                 // this will ensure we don't keep a reference due to callbacks
                return;
            }

            List <PendingTask> pendingTasksCopy;

            lock (_pendingTasksLock)
            {
                pendingTasksCopy = _pendingTasks.ToList();
            }
            foreach (var pendingTask in pendingTasksCopy)
            {
                if (pendingTask.ImageLoadingTask != null && pendingTask.ImageLoadingTask.UsesSameNativeControl(task))
                {
                    pendingTask.ImageLoadingTask.CancelIfNeeded();
                }
            }

            bool loadedFromCache = false;

            if (task.CanUseMemoryCache())
            {
                loadedFromCache = await task.PrepareAndTryLoadingFromCacheAsync().ConfigureAwait(false);
            }

            if (loadedFromCache)
            {
                if (task.Parameters.OnFinish != null)
                {
                    task.Parameters.OnFinish(task);
                }

                task.Dispose();
                return;                 // image successfully loaded from cache
            }

            if (task.IsCancelled || _pauseWork)
            {
                task.Parameters.Dispose();                 // this will ensure we don't keep a reference due to callbacks
                return;
            }

            QueueAndGenerateImage(task);
        }
コード例 #4
0
        private async Task LoadImageAsync(IImageLoaderTask task)
        {
            if (task.IsCancelled)
            {
                task.Parameters?.Dispose(); // this will ensure we don't keep a reference due to callbacks
                return;
            }

            if (!task.Parameters.Preload)
            {
                lock (_pendingTasksLock)
                {
                    foreach (var pendingTask in _pendingTasks.ToList()) // FMT: here we need a copy since cancelling will trigger them to be removed, hence collection is modified during enumeration
                    {
                        if (pendingTask.ImageLoadingTask != null && pendingTask.ImageLoadingTask.UsesSameNativeControl(task))
                        {
                            pendingTask.ImageLoadingTask.CancelIfNeeded();
                        }
                    }
                }
            }

            bool loadedFromCache = await task.PrepareAndTryLoadingFromCacheAsync().ConfigureAwait(false);

            if (loadedFromCache)
            {
                if (task.Parameters.OnFinish != null)
                {
                    task.Parameters.OnFinish(task);
                }

                task.Dispose();
                return; // image successfully loaded from cache
            }

            if (task.IsCancelled || _pauseWork)
            {
                task.Parameters?.Dispose(); // this will ensure we don't keep a reference due to callbacks
                return;
            }

            QueueAndGenerateImage(task);
        }
コード例 #5
0
        private async Task LoadImageAsync(IImageLoaderTask task)
        {
            if (task.IsCancelled)
            {
                task.Parameters.Dispose(); // this will ensure we don't keep a reference due to callbacks
                return;
            }

            if (!task.Parameters.Preload)
            {
                foreach (var pendingTask in _pendingTasks)
                {
                    if (pendingTask.Value.ImageLoadingTask != null && pendingTask.Value.ImageLoadingTask.UsesSameNativeControl(task))
                    {
                        pendingTask.Value.ImageLoadingTask.CancelIfNeeded();
                    }
                }
            }

            bool loadedFromCache = await task.PrepareAndTryLoadingFromCacheAsync().ConfigureAwait(false);

            if (loadedFromCache)
            {
                if (task.Parameters.OnFinish != null)
                {
                    task.Parameters.OnFinish(task);
                }

                task.Dispose();
                return; // image successfully loaded from cache
            }

            if (task.IsCancelled || _pauseWork)
            {
                task.Parameters.Dispose(); // this will ensure we don't keep a reference due to callbacks
                return;
            }

            QueueAndGenerateImage(task);
            return;
        }
コード例 #6
0
		/// <summary>
		/// Schedules the image loading. If image is found in cache then it returns it, otherwise it loads it.
		/// </summary>
		/// <param name="task">Image loading task.</param>
		public async void LoadImage(IImageLoaderTask task)
		{
			if (task == null)
				return;

			if (task.IsCancelled)
			{
				task.Parameters.Dispose(); // this will ensure we don't keep a reference due to callbacks
				return;
			}

			List<PendingTask> pendingTasksCopy;
			lock (_pendingTasksLock)
			{
				pendingTasksCopy = _pendingTasks.ToList();
			}
			foreach (var pendingTask in pendingTasksCopy)
			{
				if (pendingTask.ImageLoadingTask != null && pendingTask.ImageLoadingTask.UsesSameNativeControl(task))
					pendingTask.ImageLoadingTask.CancelIfNeeded();
			}

			bool loadedFromCache = false;
			if (task.CanUseMemoryCache())
			{
				loadedFromCache = await task.PrepareAndTryLoadingFromCacheAsync().ConfigureAwait(false);
			}

			if (loadedFromCache)
			{
				if (task.Parameters.OnFinish != null)
					task.Parameters.OnFinish(task);
				
				task.Dispose();
				return; // image successfully loaded from cache
			}
			
			if (task.IsCancelled || _pauseWork)
			{
				task.Parameters.Dispose(); // this will ensure we don't keep a reference due to callbacks
				return;
			}

			QueueAndGenerateImage(task);
		}
コード例 #7
0
		/// <summary>
		/// Schedules the image loading. If image is found in cache then it returns it, otherwise it loads it.
		/// </summary>
		/// <param name="task">Image loading task.</param>
		public async void LoadImage(IImageLoaderTask task)
		{
			if (task == null)
				return;

			if (task.IsCancelled)
			{
				task.Parameters.Dispose(); // this will ensure we don't keep a reference due to callbacks
				return;
			}

			bool loadedFromCache = await task.PrepareAndTryLoadingFromCacheAsync().ConfigureAwait(false);
			if (loadedFromCache)
			{
				if (task.Parameters.OnFinish != null)
					task.Parameters.OnFinish(task);

				task.Parameters.Dispose(); // this will ensure we don't keep a reference due to callbacks
				return; // image successfully loaded from cache
			}
			
			if (task.IsCancelled || _pauseWork)
			{
				task.Parameters.Dispose(); // this will ensure we don't keep a reference due to callbacks
				return;
			}

			QueueAndGenerateImage(task);
		}
コード例 #8
0
        private async Task LoadImageAsync(IImageLoaderTask task)
        {
            if (task.IsCancelled)
            {
                task.Parameters?.Dispose(); // this will ensure we don't keep a reference due to callbacks
                return;
            }

            if (!task.Parameters.Preload)
            {
                lock (_pendingTasksLock)
                {
                    foreach (var pendingTask in _pendingTasks.ToList()) // FMT: here we need a copy since cancelling will trigger them to be removed, hence collection is modified during enumeration
                    {
                        if (pendingTask.ImageLoadingTask != null && pendingTask.ImageLoadingTask.UsesSameNativeControl(task))
                            pendingTask.ImageLoadingTask.CancelIfNeeded();
                    }
                }
            }

            bool loadedFromCache = await task.PrepareAndTryLoadingFromCacheAsync().ConfigureAwait(false);
            if (loadedFromCache)
            {
                if (task.Parameters.OnFinish != null)
                    task.Parameters.OnFinish(task);

                task.Dispose();
                return; // image successfully loaded from cache
            }

            if (task.IsCancelled || _pauseWork)
            {
                task.Parameters?.Dispose(); // this will ensure we don't keep a reference due to callbacks
                return;
            }

            QueueAndGenerateImage(task);
        }