firebase / firebase-admin-dotnet

Firebase Admin .NET SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
367 stars 131 forks source link

code at sending stucked #190

Closed NaserKhoshfetrat closed 4 years ago

NaserKhoshfetrat commented 4 years ago

at line string response = await FirebaseMessaging.DefaultInstance.SendAsync(message).ConfigureAwait(true); my code stuck , there is no error or response

`public async Task SendToTokenAsync(string registrationToken, Dictionary<string, string> data) { // [START send_to_token] var message = new Message() { Data = data, Token = registrationToken, };

        // Response is a message ID string.
        string response = await FirebaseMessaging.DefaultInstance.SendAsync(message).ConfigureAwait(true);
        return response;
        // [END send_to_token]
    }`

I have initialized firebase credential in global.asax with below code

` private void InitSdkWithDefaultConfig(string credentialPath) { var credential = GoogleCredential.FromFile(credentialPath); // [START initialize_sdk_with_default_config] FirebaseApp.Create(new AppOptions() { Credential = credential, });

        Debug.WriteLine(System.Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS"));
        // [END initialize_sdk_with_default_config]
    }`

ps i've called via rest service, and it was working but i can't solve how to call via SDK

if i set ConfigureAwait(false) it is working properly

hiranya911 commented 4 years ago

You should set ConfigureAwait(false) if you have any UI code: https://medium.com/bynder-tech/c-why-you-should-use-configureawait-false-in-your-library-code-d7837dce3d7f

PS: It solely depends on how threads are managed in your particular application. But if your application seems stuck that means it's deadlocked, and you have to use ConfigureAwait(false) to avoid it.

NaserKhoshfetrat commented 4 years ago

thank you for sharing this article