Rusty Well-Known Member Licensed User Longtime User Mar 20, 2012 #1 Is there a way to have a service module be started and "sit idle" until the main "tweaks" it to do it's function. For example, I created a service module that plays audio. I need the user experience to be fast, but I need the service module to play audio only when the user touches a view. I can make the service module run every 500 milliseconds looking for audio file(s) to play, but this seems wasteful. Can the Service module be stimulated to do its functions from within main, but otherwise sit "idle"? Thanks
Is there a way to have a service module be started and "sit idle" until the main "tweaks" it to do it's function. For example, I created a service module that plays audio. I need the user experience to be fast, but I need the service module to play audio only when the user touches a view. I can make the service module run every 500 milliseconds looking for audio file(s) to play, but this seems wasteful. Can the Service module be stimulated to do its functions from within main, but otherwise sit "idle"? Thanks
thedesolatesoul Expert Licensed User Longtime User Mar 20, 2012 #2 Just call StartService(service) whenever you need to (like a click etc) from Main. Upvote 0
Rusty Well-Known Member Licensed User Longtime User Mar 20, 2012 #3 Thanks, So does this mean repetitively using StartService for the same service does not create multiple instances, it merely "invokes" the service? Obviously, using this method, I shouldn't use startserviceat from within the service, correct? Upvote 0
Thanks, So does this mean repetitively using StartService for the same service does not create multiple instances, it merely "invokes" the service? Obviously, using this method, I shouldn't use startserviceat from within the service, correct?
thedesolatesoul Expert Licensed User Longtime User Mar 20, 2012 #4 Yes, it just activates the instance of the service. There is always only one instance of the service. You can use StartServiceAt from within the service. I use it to schedule the next service start (after some time). But in your case I think you do not need it. Once the service has executed everything in Service_Start it is pretty much dead to you and the OS will clean it up if it needs memory. You can used IsPaused(service) to check if it is already running or not. (Tip courtesy of corwin42!) Upvote 0
Yes, it just activates the instance of the service. There is always only one instance of the service. You can use StartServiceAt from within the service. I use it to schedule the next service start (after some time). But in your case I think you do not need it. Once the service has executed everything in Service_Start it is pretty much dead to you and the OS will clean it up if it needs memory. You can used IsPaused(service) to check if it is already running or not. (Tip courtesy of corwin42!)
Rusty Well-Known Member Licensed User Longtime User Mar 20, 2012 #5 Thanks! This works perfectly. Upvote 0