locked
Application Lifecycle & Background Task RRS feed

  • Question

  •  

    Hi,

     

    What's the best way to write a background task that periodically wakes up and sends some data to a server?  I use C#.  And I would appreciate help on the timer portion.

     

    1. Form Timer or System Timer?

    2. How does a Windows Mobile App get shutdown/closed?  I assume that as long as the app is running, even if it is in the background (after user clicks X), form timer would still be valid and the app can access the GPS device and send data in the background?

    3. Can someone point me to docs on the lifecycle of an app?  Ie. how it got started, put in background / foreground and what the app can do in each state?

     

    Thank-you!

    Tuesday, August 7, 2007 6:19 AM

Answers

  • Hi,

     

     Apollo Strong wrote:
    What's the best way to write a background task that periodically wakes up and sends some data to a server?

     

    Your ideas of using a System.Windows.Forms.Timer appears to be a workable solution if you can guarentee that your application is always running.

     

    If the timer needs to trigger while the device is suspended (such as when the user stops working with the PDA and it turns off automatically), or the user may exit your application, you will need to look into alternative solutions such as the CERunAppAtTime API (see the following thread for pointers to help on using this API http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1714606&SiteID=1

     Apollo Strong wrote:
    How does a Windows Mobile App get shutdown/closed?  I assume that as long as the app is running, even if it is in the background (after user clicks X), form timer would still be valid and the app can access the GPS device and send data in the background?

     

    Yes this is a correct assumption. The (X) icon just pushes the window to the back of the Z-order. So any form timers, or other logic within your application will continue to run. The application is simply hidden behind another application.

     

     Apollo Strong wrote:
    Can someone point me to docs on the lifecycle of an app?  Ie. how it got started, put in background / foreground and what the app can do in each state?

     

    There are only essentially two main states you need to worry about as an application developer.

    • Running - your application has been launched and may be "hiding" (if minimised via the (X) icon). In this state all your application code will still function.
    • Suspended - the device has gone to sleep, and all code within your application stops running until the device is turned back on. Typically the device will turn back on due to the power button being pressed, however certain events (such as apps registered via CeRunAppAtTime needing to run) may also automatically turn the device back on.

    Hope this helps,
    Christopher Fairbairn

    Wednesday, August 8, 2007 12:29 AM

All replies

  • Hi,

     

     Apollo Strong wrote:
    What's the best way to write a background task that periodically wakes up and sends some data to a server?

     

    Your ideas of using a System.Windows.Forms.Timer appears to be a workable solution if you can guarentee that your application is always running.

     

    If the timer needs to trigger while the device is suspended (such as when the user stops working with the PDA and it turns off automatically), or the user may exit your application, you will need to look into alternative solutions such as the CERunAppAtTime API (see the following thread for pointers to help on using this API http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1714606&SiteID=1

     Apollo Strong wrote:
    How does a Windows Mobile App get shutdown/closed?  I assume that as long as the app is running, even if it is in the background (after user clicks X), form timer would still be valid and the app can access the GPS device and send data in the background?

     

    Yes this is a correct assumption. The (X) icon just pushes the window to the back of the Z-order. So any form timers, or other logic within your application will continue to run. The application is simply hidden behind another application.

     

     Apollo Strong wrote:
    Can someone point me to docs on the lifecycle of an app?  Ie. how it got started, put in background / foreground and what the app can do in each state?

     

    There are only essentially two main states you need to worry about as an application developer.

    • Running - your application has been launched and may be "hiding" (if minimised via the (X) icon). In this state all your application code will still function.
    • Suspended - the device has gone to sleep, and all code within your application stops running until the device is turned back on. Typically the device will turn back on due to the power button being pressed, however certain events (such as apps registered via CeRunAppAtTime needing to run) may also automatically turn the device back on.

    Hope this helps,
    Christopher Fairbairn

    Wednesday, August 8, 2007 12:29 AM
  • Thank-you!

     

    Wednesday, August 8, 2007 3:41 AM