F flyingbag Member Licensed User Longtime User Aug 6, 2012 #1 Hello, Newbie here ...again -I have Service A that starts Service B after receiving event "X" (lets say event is SMS received) - Service A also has a global boolean : FLAG --- Service B has a timer in it and does Task B ---- Service B then changes status of FLAG to false -------If Flag is false - service B does nothing Questions: 1) If Event X gets fired multiple times (multiple SMS arriving at the same time) will the timer in Service B work as expected? I think not - since my application does a lot of wrong things when multiple events occur - but works fine one event at a time... 2) Since the global FLAG is being modified to FALSE - any ideas how this can be handled when concurrent events occur? I hope i could illustrate my problem ... Thanks FlyingBag
Hello, Newbie here ...again -I have Service A that starts Service B after receiving event "X" (lets say event is SMS received) - Service A also has a global boolean : FLAG --- Service B has a timer in it and does Task B ---- Service B then changes status of FLAG to false -------If Flag is false - service B does nothing Questions: 1) If Event X gets fired multiple times (multiple SMS arriving at the same time) will the timer in Service B work as expected? I think not - since my application does a lot of wrong things when multiple events occur - but works fine one event at a time... 2) Since the global FLAG is being modified to FALSE - any ideas how this can be handled when concurrent events occur? I hope i could illustrate my problem ... Thanks FlyingBag
Erel B4X founder Staff member Licensed User Longtime User Aug 6, 2012 #2 Unless you are using the Threading library, your code always runs in the main thread (libraries code can run in different threads). This means that there could only be a single event running at any time. Upvote 0
Unless you are using the Threading library, your code always runs in the main thread (libraries code can run in different threads). This means that there could only be a single event running at any time.
F flyingbag Member Licensed User Longtime User Aug 6, 2012 #3 Thanks Erel, I did not want to go into threading at this stage since i am still a newbie and i think it might overcomplicate the solution I solved the problem in this way: -I have Service A that starts Service B after receiving event "X" (lets say event is SMS received) - Service A also has a global boolean : FLAG --- Service B has a timer in it and does Task B SOLUTION: Check if Timer.Enabled = true - then wait till Timer.Enabled = false This way i am making sure that the timer always runs... ---- Service B then changes status of FLAG to false -------If Flag is false - service B does nothing Now no error is caused with concurrent events - since i am waiting for the events to be processed sequentially. My app is not mission critical - so this solution seems to work ok. Also my timer is only 5 seconds so not really an issue... Thank you! Last edited: Aug 6, 2012 Upvote 0
Thanks Erel, I did not want to go into threading at this stage since i am still a newbie and i think it might overcomplicate the solution I solved the problem in this way: -I have Service A that starts Service B after receiving event "X" (lets say event is SMS received) - Service A also has a global boolean : FLAG --- Service B has a timer in it and does Task B SOLUTION: Check if Timer.Enabled = true - then wait till Timer.Enabled = false This way i am making sure that the timer always runs... ---- Service B then changes status of FLAG to false -------If Flag is false - service B does nothing Now no error is caused with concurrent events - since i am waiting for the events to be processed sequentially. My app is not mission critical - so this solution seems to work ok. Also my timer is only 5 seconds so not really an issue... Thank you!