Skip to content

Improve async usage #1

@GeertvanHorrik

Description

@GeertvanHorrik

For example, this code:

    using System.Threading.Tasks;
    using Windows.Storage;

    public class ImageCache
    {
        public static async Task<StorageFile> Load(string url)
        {
            return await Load(url, null);
        }

        public static async Task<StorageFile> Load(string url, Crop crop)
        {
            return await Loader.CacheManager(url, crop);
        }

Can be rewritten as:

    public class ImageCache
    {
        public static Task<StorageFile> LoadAsync(string url)
        {
            return LoadAsync(url, null);
        }

        public static Task<StorageFile> LoadAsync(string url, Crop crop)
        {
            return Loader.CacheManager(url, crop);
        }
  1. (I think) it's best to postfix async methods with 'Async'
  2. Don't use async Task if you are only awaiting a single task, just return the task (saves a task object that also needs garbage collecting, etc)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions