0

I'm trying to build an app that detects product from android and send it in real-time to the desktop application via firebase but I don't know firebase doesn't work in real-time when I get value on C# app (I mean when I change values it doesn't change in the app automatically.)

Rq: I'm using FireSharp reference and My code for receiving:

public void getdata()
  {
     var res = client.Get(@"Store/");
     Store str = res.ResultAs<Store>();
     store.Text = str.Tags;
     nb.Text = str.nb;
   }
Rajan Mishra
  • 1,178
  • 2
  • 14
  • 30
ala freestyle
  • 109
  • 10
  • So, you're getting something from your Firebase store, changing a value, and you are asking why it doesn't automatically update in Firebase too? What do you mean that Firebase doesn't work in real-time? –  Jan 08 '20 at 14:25
  • I mean firebase at general changes your result when the database values changes. For example in android, we have public void onDataChange(DataSnapshot dataSnapshot) that execute automatically when data in firebase changes so U don't need to check by user self if data changes or not. – ala freestyle Jan 08 '20 at 14:39

1 Answers1

3

By calling the Get method, you're calling the server to get the data only once.

If you want to instead get the data now and then continue to listen for updates, use the OnAsync method. From the linked documentation:

EventStreamResponse response = await _client.OnAsync("chat", (sender, args, context) => {
       System.Console.WriteLine(args.Data);
});

//Call dispose to stop listening for events
response.Dispose();
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Even I Use : ` private async void button1_Click(object sender, EventArgs e) { IFirebaseClient client = new FirebaseClient(ifc); FirebaseResponse response = await client.GetAsync("Store/"); Store str = response.ResultAs(); //The response will contain the data being retreived store.Text = str.Tags; nb.Text = str.nb; }` Text view don't Update automaticlly – ala freestyle Jan 09 '20 at 08:43
  • If you use the code in my answer, does it print the new data in the console? Because if it does, you at least know that the database connection is getting its updates, and the problem is in the UI part of your code. – Frank van Puffelen Jan 09 '20 at 14:57
  • that's mean if I use it to update my local database it works fine? – ala freestyle Jan 10 '20 at 14:56
  • @FrankvanPuffelen I tried this but didn't work. Does the "chat"means the path ? – Chamod Dec 19 '21 at 07:09
  • Yes, that is the path you are reading from. – Frank van Puffelen Dec 19 '21 at 16:52