"Task" does not contain definition for "CompletedTask" for C #

I am following the tutorial at https://discord.foxbot.me/docs/guides/getting_started/intro.html in tee and still I get an error when I try to use

return Task.CompletedTask

      

and i am getting this error

'Task' does not contain a definition for 'CompletedTask'

      

I AM

using System.Threading.Tasks

      

+3


source to share


3 answers


Task.CompletedTask

is a static property added in .NET 4.6. Here is his source and here is his MSDN page that shows the minimum version of the framework.

Just for completeness, this is how you change the version of the .NET Framework you are using in your project.



Project Properties, Target Framework

+9


source


If you are unable to update your .NET Framework version, simply



replace Task.CompletedTask

with Task.FromResult(0)

.

+3


source


From this documentation , the Log () function has two parameters (LogMessage, Task). I believe there is a mistake in the tutorial and they forgot to enable the Task parameter. I would suggest using this instead.

private Task Log(LogMessage msg,Task task)
        {
            Console.WriteLine(msg.ToString());
            return Task.CompletedTask;
        }

      

0


source







All Articles