locked
await namespace RRS feed

  • Question

  • I want to use await to wait for the asynchronous termination of a task without blocking the UI but VS tells me that "await" is not recognized. I have turned on the Microsoft.Bcl.AsyncInterfaces reference but it still doesn't work.What is the await NameSpace or reference to add in VS 2019?
    Monday, November 16, 2020 5:47 AM

Answers

  • Hi zequion1,

    It seems that await should be used with async, try to add async to the method.

    Add async:

    Hope this could be helpful.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by zequion1 Monday, November 16, 2020 9:01 AM
    Monday, November 16, 2020 8:46 AM

All replies

  • Show us your code.  Have you set a particular C# version in your settings?  "await" is a compiler statement that does not depend on references or assemblies at all.

    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Monday, November 16, 2020 6:34 AM
  • I want to use await to wait for the asynchronous termination of a task without blocking the UI but VS tells me that "await" is not recognized. I have turned on the Microsoft.Bcl.AsyncInterfaces reference but it still doesn't work.What is the await NameSpace or reference to add in VS 2019?

    Do you have this in your code?

    using System.Threading.Tasks;

    Have you specified async for the task?

    You should show at least a snippet of the code you are trying to use.

    You should post a sample of the *exact* error message (copy & paste),
    not just a paraphrase or abbreviation.

    Could you not find what you are looking for in the docs?

    await operator (C# reference)
    https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/await

    Asynchronous programming with async and await
    https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/

    - Wayne

    Monday, November 16, 2020 6:37 AM
  • C# version: In "Project", "Compilation", "Advanced" does not show me the C # version and indicates "Automatically selected according to the version of the framework".

    Does not work with "using System.Threading.Tasks;"

    in app.config:

     <system.codedom>
        <compilers>
          <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
          <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
        </compilers>
      </system.codedom>



    • Edited by zequion1 Monday, November 16, 2020 6:50 AM
    Monday, November 16, 2020 6:47 AM
  • Hi zequion1,

    It seems that await should be used with async, try to add async to the method.

    Add async:

    Hope this could be helpful.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by zequion1 Monday, November 16, 2020 9:01 AM
    Monday, November 16, 2020 8:46 AM