I mean with overwritting the old result, that in the end i have to excact entries. How can I solve the problem?
When the first method enters (presumably because of a user button press) you're calling GetText()
using await
; Let's assume App.Number
is 1
when you first do this. Because of the await
execution is suspended right there until GetText()
returns, but your GUI is not! Let's assume the user presses the same button again. GetText()
will again be called and App.Number
will still be 1
because the first GetText()
hasn't yet returned. Since the query is built based on App.Number
then you're obviously going to get two identical results.
When the first GetText()
returns you're going to increment App.Number
so it's now 2
; When the second GetText()
returns the App.Number
gets implemented once more! You're not only getting the result for App.Number==1
twice, you're going to complitely skip the result for App.Number==2
!
Depending on what the meaning of those numbers is, you'd have multiple solutions: Increment App.Number
before you call GetText()
AND pass the number as a parameter, make the method non-re-entrant, whatever works for you. If for example there's some meaning in the order of the request, then the best option is to disable the button because HTTP requests sent in parallel aren't guaranteed to complete in the order they were started. For example your GetText(2)
could easily return before GetText(1)
; It's also possible that GetText(n)
might never return because of some error.
You now know why you're seeing what you're seeing, but I can't suggest a solution because I don't actually know what the correct behavior should be. That's up to you!