A13u
❔ How to close a listener firestore.
public void ListenToDocument(string collectionName, string documentId)
{
DocumentReference docRef = db.Collection(collectionName).Document(documentId);
FirestoreChangeListener listener = docRef.Listen(snapshot =>
{
Console.WriteLine("Callback received document snapshot.");
Console.WriteLine("Document exists? {0}", snapshot.Exists);
if (snapshot.Exists)
{
Console.WriteLine("Document data for {0} document:", snapshot.Id);
Dictionary<string, object> documentData = snapshot.ToDictionary();
foreach (KeyValuePair<string, object> pair in documentData)
{
Console.WriteLine("{0}: {1}", pair.Key, pair.Value);
}
}
});
listener.ListenerTask.Wait(); // Block until the listener is done
public void ListenToDocument(string collectionName, string documentId)
{
DocumentReference docRef = db.Collection(collectionName).Document(documentId);
FirestoreChangeListener listener = docRef.Listen(snapshot =>
{
Console.WriteLine("Callback received document snapshot.");
Console.WriteLine("Document exists? {0}", snapshot.Exists);
if (snapshot.Exists)
{
Console.WriteLine("Document data for {0} document:", snapshot.Id);
Dictionary<string, object> documentData = snapshot.ToDictionary();
foreach (KeyValuePair<string, object> pair in documentData)
{
Console.WriteLine("{0}: {1}", pair.Key, pair.Value);
}
}
});
listener.ListenerTask.Wait(); // Block until the listener is done
4 replies