-3

I currently have code that looks like this:

private async Task<ListFolderResult> ListFolder(DropboxClient client, string path)
{
    Console.WriteLine("--- Files ---");
    var list = await client.Files.ListFolderAsync(path);

    return list;
}

And is called like this:

var list = await ListFolder(client, path);

I would like to change that code so the call looks like this:

var list = ListFolder(client, path);

And the waiting moves to inside of the ListFolder method.

Be Kind To New Users
  • 9,672
  • 13
  • 78
  • 125

1 Answers1

-2

This is working for me in a console app, but I will be very happy to delete this answer if someone posts a more general answer.

private ListFolderResult ListFolder(DropboxClient client, string path)
{
    Console.WriteLine("--- Files ---");
    var list = client.Files.ListFolderAsync(path);
    list.Wait();

    return list.Result;
}
Be Kind To New Users
  • 9,672
  • 13
  • 78
  • 125
  • if there is something wrong with this answer then please comment or post an another answer. – Be Kind To New Users Sep 23 '17 at 23:02
  • Suggesting code that almost guaranteed to deadlock in most cases (except console or unit test) without good warning makes this suggestion bad answer. (ignoring fact that there are tons of better answers how to call async code synchronously) – Alexei Levenkov Sep 23 '17 at 23:13
  • 1
    BTW: `return client.Files.ListFolderAsync(path).Result` is enough. No need for *Wait*. Since now it is one line function, no need it to be a separate function – Eser Sep 23 '17 at 23:19
  • @Eser - post that as an answer and I will accept it and delete my answer. – Be Kind To New Users Sep 23 '17 at 23:46