Marc (34) [Avatar] Offline
#1
Hi,
You recommend registering all the Services as singletons with the IoC container.
You recommend implementing longer running tasks as multiple background threads.

I'm concerned about the instance variables in the classes.
Is there any Xamarin/Android "magic" that makes the single object thread-safe?
Is that my responsibility?

I started out as an operating system programmer on an early timesharing system.
I have always been a bit skeptical of attempts by application programmers to run things "in parallel".
Once the service is "safe", isn't that a euphemism for single threaded, but with all the complexity of apparent parallelism?

Thx,
M.
Jim Bennett (86) [Avatar] Offline
#2
No magic, you'll need to manage this yourself.

.NET has a range of classes to help with concurrency, such as concurrent collections. You can read more on concurrent collections at https://aka.ms/Krdr7g
You can also use NuGet packages like PunchClock (https://github.com/paulcbetts/punchclock) to help serialize access.