Question regarding concurrently running a service

flyingbag

Member
Licensed User
Longtime User
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
 

flyingbag

Member
Licensed User
Longtime User
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:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…