Skip to content
This repository has been archived by the owner. It is now read-only.
This repository has been archived by the owner. It is now read-only.

Analyzer for wrong usage of async methods #164

Open
@Rpinski

Description

@Rpinski

Example async method:

        public Task<string> DoSomethingAsync(string str)
        {
            return Task.FromResult(str);
        }

Examples of wrong usage:

        public async Task Scenario1Async()
        {
            var usedCorrectly = await DoSomethingAsync("helloworld");

            // obviously wrong, but could happen for fire-and-forget cases where you don't check eg the boolean result
            var blatantlywrong = DoSomethingAsync("get it going");
        }

        public async Task Scenario2Async()
        {
            var usedCorrectly = await DoSomethingAsync("helloworld");

            // If you have models that happen to have an Id property (very likely when working with dbs)
            var stillwrong = DoSomethingAsync("guess what");
            var x = stillwrong.Id;
        }

        public void Scenario3()
        {
            // Creatively wrong
            List<string> somestrings = new List<string>() { "Hello", "World" };
            var result = somestrings.Select(DoSomethingAsync).ToList();
            Console.WriteLine(result[1]);
        }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions