Skip to content
This repository has been archived by the owner on Nov 6, 2024. It is now read-only.

Xamarin.Firebase.Database Adding Listeners Question #505

Open
fdhsdrdark opened this issue Aug 14, 2021 · 1 comment
Open

Xamarin.Firebase.Database Adding Listeners Question #505

fdhsdrdark opened this issue Aug 14, 2021 · 1 comment

Comments

@fdhsdrdark
Copy link

fdhsdrdark commented Aug 14, 2021

Hello,

Not an issue, a question actually.

When adding a listener for an event on Firebase I assume a communication with Firebase actually happens behind the scenes.
Therefore, ideally, the event attaching operation should be made on backround thread - right?
For example by calling the operation inside the Task.Run method - in code something like the code presented below.
Is that the case or this is not really required since it's handled by Xamarin.Firebase?

      Task.Run(()=>{ 
      
      FirebaseStatusDatabaseReference = 
      MyFirebaseClient.Instance.GetReference("MyCollectionName").Child("MyKey").Child("Status");

	FirebaseStatusChangeEventListener = new MyFirebasetStatusChangeListener();
	FirebaseStatusDatabaseReference.AddValueEventListener(FirebaseStatusChangeEventListener);
            
     });

Thanks very much.

@fdhsdrdark
Copy link
Author

Answering my own question for anyone wondering about this. It seems that firebase, and therefore Xamarin.Firebase.Database does this by default. According to this post you the query is executed on a background thread and the event methods return on the UI thread.
https://stackoverflow.com/questions/35777400/firebase-android-ondatachange-event-always-executed-in-main-ui-thread

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

No branches or pull requests

1 participant