×

Discussion Board

Results 1 to 15 of 25

Hybrid View

  1. #1
    Regular Contributor
    Join Date
    Dec 2012
    Posts
    66

    Saving data before exiting in PeriodicTask

    As the documentation says, OS provides you with merely 25 sec to complete your work on PeriodicTask launch.
    I have a long list of commands to be sent to the server in the background. So how do i make sure to save back the unsent stuff back to IsolatedStorage before my 25 sec gets over. Do i get terminating/finishing or some similar notification?

    And while searching for this i came across this. Which says if NotifyComplete() is not called in the OnInvoke() i may face problems for subsequent PeriodicTask launches. So how do i make sure to call NotifyComplete() every time.

    Regards

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,771

    Re: Saving data before exiting in PeriodicTask

    "Make sure to save back the unsent stuff" is something what can not be done in a reliable way. However you can certainly do exactly the opposite: send whatever you can, and only remove the stuff then, perhaps waiting for some acknowledgement. You may end up sending some commands multiple time so having some unique identifier for them is probably a good idea. Then the receiving party can discard doubles, but re-send the acknowledgement so the command will disappear from the queue.
    For the 25 seconds you should simply measure it. You certainly have a loop if you are handling a list. Store a timestamp at the beginning, and bail out from the loop if more than -say- 23 seconds have passed.

  3. #3
    Regular Contributor
    Join Date
    Dec 2012
    Posts
    66

    Re: Saving data before exiting in PeriodicTask

    Hi wizard_hu_, thanks for your response. And yes i thought about this approach but 25s is very small time and writing to isolated storage is a slow process, after all its writing to a file. So writing to isolated storage every time i get a response will waste few seconds from those 25 sec every time. So i was thinking if i load all commands in memory, send as much as i can in 25 sec and write back only once the remaining commands will help in utilizing those 25 sec more efficiently. That's why i was wondering if i can get some kind of 25 sec finishing notification.
    Please correct me if i am mistaken.

    Regards

  4. #4
    Regular Contributor
    Join Date
    Dec 2012
    Posts
    66

    Re: Saving data before exiting in PeriodicTask

    Quote Originally Posted by wizard_hu_ View Post
    For the 25 seconds you should simply measure it. You certainly have a loop if you are handling a list. Store a timestamp at the beginning, and bail out from the loop if more than -say- 23 seconds have passed.
    Yes i have a unique ID associated with every command and i wait for the acknowledgement before sending next command but i am not too much aware with c#. I will be glad if you can explain on this with some code.

  5. #5
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,771

    Re: Saving data before exiting in PeriodicTask

    I really doubt that there would be any extra notification, but I actually do not know for sure.
    Since you have unique ID-s, and thus the server can filter out duplicate commands, there is a lot of space for experimentation. Like you can collect the acknowledgements, and delay the file operation for the last few seconds, or schedule a couple write-back operations, for every 5 seconds for example. There will be duplicates remaining but the server can recognize them.
    Also note that seconds are a short time for you to write megabytes of data on a piece of paper, but phones are a lot faster, you can actually create some benchmarking code (or just look up one on the Internet) if you want to see how much.

  6. #6
    Regular Contributor
    Join Date
    Dec 2012
    Posts
    66

    Re: Saving data before exiting in PeriodicTask

    Quote Originally Posted by wizard_hu_ View Post
    Like you can collect the acknowledgements, and delay the file operation for the last few seconds
    That's the question. How do i achieve this? How do i know i have last few seconds remaining? Do OS notifies me? if yes how? if no, shall i run my own timer and what's the best way to run a timer C#?

  7. #7
    Regular Contributor
    Join Date
    Sep 2012
    Location
    Morocco
    Posts
    298

    Re: Saving data before exiting in PeriodicTask

    Quote Originally Posted by vinayppatil View Post
    That's the question. How do i achieve this? How do i know i have last few seconds remaining? Do OS notifies me? if yes how? if no, shall i run my own timer and what's the best way to run a timer C#?
    As Wizard_hu_ stated before, you need to store the timespan on the beginning of your OnInvoke method,
    Code:
    DateTime onInvokeStart = DateTime.Now;
    while((DateTime.Now-onInvokeStart).TotalSeconds <= 23) // DateTime.Now-onInvokeStart will return a TimeSpan type
    {
    // do you work
    }
    NotifyComplete();

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
  •  
×