×

Discussion Board

Page 2 of 2 FirstFirst 12
Results 16 to 25 of 25
  1. #16
    Nokia Developer Champion
    Join Date
    Sep 2012
    Location
    Morocco
    Posts
    296

    Re: Saving data before exiting in PeriodicTask

    Long data processing in Windows phone periodic task / Background Agent
    But still I prefer Handing potentially long running periodic tasks on Windows Phone

  2. #17
    Nokia Developer Moderator
    Join Date
    Feb 2011
    Location
    Portugal
    Posts
    948

    Re: Saving data before exiting in PeriodicTask

    Perhaps:

    How to handle Data storage on Periodic Tasks and App termination

    may it be a Task or an App being terminated, the same rule applies. We have just a few seconds to save anything that we need to save. So the article would be interesting for both scenarios

  3. #18
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    511

    Re: Saving data before exiting in PeriodicTask

    To my knowledge you are not guaranteed to get 25 seconds of time when being invoked as a Periodic Task, rather every 30 minutes Windows Phone runs the available Periodic Tasks for a total of 25 seconds. So your task might get run after another task that already consumed some of the alotted time which would mean that you don't save your progress if you're waiting for the end of the time slot to do so.

    Also hard coding those "system constants" into your App isn't the best idea anyway because it is entirely possible that they will change in the future (e.g. 10 seconds every 15 minutes or something like that).

  4. #19
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,694

    Re: Saving data before exiting in PeriodicTask

    Could you link some related documentation?
    Just general thinking: background agents are supposed to actually do something. If the OS shuts them down at random times, like after a second, and re-start from scratch say 4 minutes later, that would render them completely unusable. Added that there is no notifications about these happenings.

  5. #20
    Registered User
    Join Date
    Jan 2009
    Location
    Melbourne, Australia
    Posts
    2,571

    Re: Saving data before exiting in PeriodicTask

    So looking at the titles
    * Handing potentially long running periodic tasks on Windows Phone
    * How to manage periodic tasks in Windows Phone
    Either of these are OK. I would expect the first to have a focus on the problem case of the periodic task not completing and the second to cover all aspects of using periodic tasks (at which point you might call it "Periodic Tasks on Windows Phone"). So which to use depends on how general the topic would be - obviously I'd like the second but it is harder to write.

    Joao's suggestion:
    * How to Manage Data storage on Periodic Tasks and App termination
    What I don't like about this is that data storage is what we do to ensure safe sending of data - so we have a title that talks about a solution but not a problem (ie why do we need to save data). Also we're looking at device power off as a case too.
    What I do like about it is that it covers a smaller scope - you don't need to concentrate so much on the periodic task aspect of calling NotifyComplete because this topic is more about guaranteeing you know what data has been sent and that you still have backup even if the app or device is shut down.

    How about
    * "How to safely store transient data during Periodic Tasks"
    * "Storing transient data across Periodic Tasks on Windows Phone"
    * ?

    Note, this is not the topic currently written about on wiki but IMO this article premature based on SB_Dev's comments. There might well be 2 topics here. I would hope Joao might write the one on his solution?

  6. #21
    Registered User
    Join Date
    Jan 2009
    Location
    Melbourne, Australia
    Posts
    2,571

    Re: Saving data before exiting in PeriodicTask

    Quote Originally Posted by SB Dev View Post
    To my knowledge you are not guaranteed to get 25 seconds of time when being invoked as a Periodic Task, rather every 30 minutes Windows Phone runs the available Periodic Tasks for a total of 25 seconds. So your task might get run after another task that already consumed some of the alotted time which would mean that you don't save your progress if you're waiting for the end of the time slot to do so.

    Also hard coding those "system constants" into your App isn't the best idea anyway because it is entirely possible that they will change in the future (e.g. 10 seconds every 15 minutes or something like that).
    I can't find any "official" documentation. This blog states "They can be set to run as often as 30 minutes, but that time may drift by as much as 10 minutes. They may not run every cycle, depending on how busy the operating system is. They'll be terminated if they run longer than 25 seconds, but may be terminated sooner if the operating system decides it needs to."

    Even though I doubt your suspicion that all task run in the 25 second period, and I suspect that real world testing would show that in most cases they would run like clockwork, your key point is still valid - as a developer you can't assume how much time you've got or that you'll be called at all. Hard coding is therefore not smart.

    What are our options then - from the beginning of the thread it sounded like there would be problems if you don't call NotifyComplete, but what is your choice here since in theory there is no way to know a safe time to call it? Can you call it early after each bit is processed or will that prematurely end your execution?

    What is very clear is that you can never assume that all data is saved/sent or that any processing is done. So if it is important that the data be saved (as in a "data send to server" scenario) this needs to be managed. I think that is a separate article that Joao could? write? Aspect of calling NotifyComplete might be added towards end.

    Regards
    Hamish

  7. #22
    Registered User
    Join Date
    Jan 2009
    Location
    Melbourne, Australia
    Posts
    2,571

    Re: Saving data before exiting in PeriodicTask

    So do we know what happens if you don't call NotifyComplete() ? If this is not really a problem then you'd ignore this task unless you're really complete, and otherwise just follow some strategy like Joao's to be fault tolerant.

  8. #23
    Nokia Developer Champion
    Join Date
    Sep 2012
    Location
    Morocco
    Posts
    296

    Re: Saving data before exiting in PeriodicTask

    Quote Originally Posted by hamishwillee View Post
    I can't find any "official" documentation. This blog states "They can be set to run as often as 30 minutes, but that time may drift by as much as 10 minutes. They may not run every cycle, depending on how busy the operating system is. They'll be terminated if they run longer than 25 seconds, but may be terminated sooner if the operating system decides it needs to."
    http://msdn.microsoft.com/en-us/libr...PeriodicAgents
    Quote Originally Posted by hamishwillee View Post
    Even though I doubt your suspicion that all task run in the 25 second period, and I suspect that real world testing would show that in most cases they would run like clockwork, your key point is still valid - as a developer you can't assume how much time you've got or that you'll be called at all. Hard coding is therefore not smart.
    Quote Originally Posted by hamishwillee View Post
    So do we know what happens if you don't call NotifyComplete() ? If this is not really a problem then you'd ignore this task unless you're really complete, and otherwise just follow some strategy like Joao's to be fault tolerant.
    If you don't call NotifyComplete() the task runned by the background agent will simply gets terminated.
    as stated here the notifyComplete method "should" be implemented only to tell the system that it's done and can go allow resources to other background agents
    When your Scheduled Task code has completed, you should call NotifyComplete() to let the operating system know that you no longer need to execute. This allows the operating system to attempt to schedule other agents.

  9. #24
    Registered User
    Join Date
    Jan 2009
    Location
    Melbourne, Australia
    Posts
    2,571

    Re: Saving data before exiting in PeriodicTask

    Thank you. Great to know. Vinay is still working on the article but I think it is pretty clear what it should look like now.

  10. #25
    Registered User
    Join Date
    Jan 2009
    Location
    Melbourne, Australia
    Posts
    2,571

    Re: Saving data before exiting in PeriodicTask

    How_to_manage_long_running_Periodic_Tasks is now complete. Can you guys please scan it for technical accuracy.

    It is now simpler and almost code free (since I think code would be use-case specific). It captures both the stated unreliability of the task and also that anecdotally they are reliable. It makes clear that for robust code if a task MUST complete that the correct strategy is to save tasks in Isolated Storage and only remove them when done.

    Thanks Vinay for your work and patience - and especially for validating that the tasks are indeed "mostly" reliable on Lumia 920.

Similar Threads

  1. XML data saving problem
    By surmitt in forum Symbian
    Replies: 2
    Last Post: 2011-10-20, 05:42
  2. Saving of data
    By zhenhan82 in forum [Archived] Flash Lite on Nokia Devices
    Replies: 6
    Last Post: 2010-04-13, 06:25
  3. Saving data to device
    By sim0nha in forum Symbian
    Replies: 2
    Last Post: 2009-07-20, 21:30
  4. Saving data
    By poodk in forum Symbian
    Replies: 9
    Last Post: 2008-10-06, 16:55
  5. Saving downloaded data
    By ins0mnia in forum Mobile Java Networking & Messaging & Security
    Replies: 6
    Last Post: 2003-08-31, 09:56

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×