Skip to content

Do not call Task.WaitAll with a single argument #33807

Closed

Description

@terrajobst

Task.Wait can be used instead.

Category: Performance

Activity

  1. added
    api-suggestion
    code-analyzer
    on Mar 19, 2020
  2. added
    untriaged
    on Mar 19, 2020
  3. added this to the Future milestone on Mar 20, 2020
  4. added
    code-fixer
    on Mar 21, 2020
  5. jeffhandley commented on Mar 21, 2020

    @jeffhandley
    Member

    Estimates:

    • Analyzer: Small
    • Fixer: Small
  6. removed
    untriaged
    on Mar 21, 2020
  7. Mrnikbobjeff commented on Aug 30, 2020

    @Mrnikbobjeff

    I have a working analyzer for this as well, if this is ready to implement. #33806 is very similar, my analyzer would offer a great basis for that issue.

  8. carlossanlop commented on Oct 30, 2020

    @carlossanlop
    Contributor

    Here is a usage example:

    using System.Threading.Tasks;
    
    namespace MyNamespace
    {
        class Sample
        {
            public static void Main()
            {
                Task task = ...;
    
                // Instead of this
                Task.WaitAll(task);
    
                // Suggest this
                task.Wait();
    
                
                // Instead of this
                Task.WaitAll(GetTask());
    
                // Suggest this
                GetTask().Wait();
            }
    
            static Task GetTask()
            {
                return ...;
            }
        }
    }
    • This analyzer should not affect any of the other WaitAll overloads, because they take a Task[]. Only this overload, which takes a params Task[] task would be affected.
    • This analyzer should also have a fixer.
    • Suggested severity: Info.
    • Suggested milestone if approved: 6.0 (seems simple to address).

    Questions

  9. added
    api-ready-for-review
    and removed
    api-suggestion
    on Oct 30, 2020
  10. added
    api-approved
    and removed
    api-ready-for-review
    on Feb 4, 2021
  11. terrajobst commented on Feb 4, 2021

    @terrajobst
    ContributorAuthor

    Video

    • Makes sense
    void M(Task task)
    {
        // Before
        Task.WaitAll(task);
    
        // After
        task.Wait();
    }
  12. added
    help wanted
    on Feb 4, 2021
  13. ryzngard commented on Feb 5, 2021

    @ryzngard

    I'll take this and #33806

  14. removed
    help wanted
    on Feb 5, 2021
  15. carlossanlop commented on Feb 5, 2021

    @carlossanlop
    Contributor

    It's yours, @ryzngard. Thanks for your help! Let us know if you have any questions.

  16. stephentoub commented on Jul 13, 2021

    @stephentoub
    Member

    This was implemented as CA1842/1843. Thanks!

  17. ghost locked as resolved and limited conversation to collaborators on Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api-approvedarea-System.Threading.Taskscode-analyzercode-fixer

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions