-1

Hi I have created an async method is c# to get all projects from VSTS.

Here is how the defenition looks like

public async Task<string> GetProjects()
{
    try
    {
        return r;
    }
    catch
    {
        return "";
    }
}

But when I tries to get the return value from it, it says The await operator can only be used with Async methods.. I didnt understand it since Im new to these async and await methods. The way I tried to access is like this

string s;

s=await GetProjects();
Sandeep Thomas
  • 4,303
  • 14
  • 61
  • 132

2 Answers2

2

If you desperately need to have an async method, you can do it like this:

return Task.FromResult("");

However, you should really read this as @PeterBons suggested

Nick
  • 4,787
  • 2
  • 18
  • 24
0

If your method uses await, it must be marked as async. You can read here why: https://blogs.msdn.microsoft.com/ericlippert/2010/11/11/asynchrony-in-c-5-part-six-whither-async/

haimb
  • 381
  • 3
  • 4