Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Program exits abruptly after the call to async method #300

Open
BlockchainDeveloper009 opened this issue Mar 25, 2022 · 1 comment
Open

Comments

@BlockchainDeveloper009
Copy link

Hello,

I am trying to use your project. Please find below code for your reference.

 public static async Task getAccounts()
        {
            

            var apiKey = "";
            var apiSecret = "";
            var passphrase = "";

            try
            {
                //create an authenticator with your apiKey, apiSecret and passphrase
                var authenticator = new Authenticator(apiKey, apiSecret, passphrase);

                //create the CoinbasePro client
                var coinbaseProClient = new CoinbasePro.CoinbaseProClient(authenticator);

                //use one of the services 
                var allAccounts = await coinbaseProClient.AccountsService.GetAllAccountsAsync(); // once this line executed, this method quits to main program. 


               console.Write("I would like to print results."); //this line is not executed.
               

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw;
            }

        }

calling main Program:

static void Main(string[] args)
{
getAccounts();
console.ReadKey(); //
}

What am i doing wrong????

@dougdellolio
Copy link
Owner

dougdellolio commented Mar 26, 2022

hi @BlockchainDeveloper009 the getAccounts() function you provided doesn't look to be returning anything but a Task. Also looks like you aren't printing the results from accounts. Here is some of your code modified:

    public class Program
    {
        public static async Task<IEnumerable<Services.Accounts.Models.Account>> getAccounts()
        {
            var apiKey = "";
            var apiSecret = "";
            var passphrase = "";

            try
            {
                var authenticator = new Authenticator(apiKey, apiSecret, passphrase);

                //create the CoinbasePro client
                var coinbaseProClient = new CoinbaseProClient(authenticator);

                //use one of the services 
                return await coinbaseProClient.AccountsService.GetAllAccountsAsync();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw;
            }
        }

        public static async Task Main(string[] args)
        {
            var accounts = await getAccounts();

            foreach (var account in accounts)
            {
                Console.WriteLine(account.Id);
            }

            Console.ReadKey();
        }
    }

hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants