locked
When save DataContext to File?

    Question

  • Hello,

    i have a little Visual Basic Application with a ListView on the MainPage. The DataContext of the MainPage is a class (say Class1) where the ListViews ItemSource is impemented as an ObservableCollection.

    The objects in the Observable Collection shall be stored in a file. I fill the collection in Class1.New. But when shall i overwrite the file from the collection? At each PropertyChanged of one of the objects in the collection?

    I like a automatic save. Don't want to need a save button.

    Thank you,
    Markus


    Friday, March 13, 2015 6:09 PM

Answers

  • Hi Markus,

    For your question one: Yes, when user manually switch to another app or desktop, suspend event is called.

    For your second question: Baskground task is the only choice, besides Windows Store App are designed to run at mobile device, save power is a consideration, we should not allow app to use too much power when they are not in front, for this reason even background task has some limitations to save power. The answer is not possible for a task like you described.

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 16, 2015 1:56 PM
    Moderator

All replies

  • The alternative way i think would be to set a flag in Class1 "Changed" and have a timer who saves the file when he find "Changed" and resets the Flag to false.

    But what is when the application ends before the timer is called? Is Class1.Finalize always be called? So that this can make the save if necessary?

    Friday, March 13, 2015 7:03 PM
  • Hi Markus222,

    I would recommend you to go through the app life cycle: Application lifecycle

    Basically we need to save data when the app is about to suspend or user want to exist the app.  

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 16, 2015 6:29 AM
    Moderator
  • Hello James,

    what is when the user Switches to another app or to the Desktop? Then shutdown the Computer. Is then the Application.Suspending Event ever called?

    Another question: When Suspended,  the App is not active. But i need a timer. Firing every Minute or so. The amount of work that need to be done then is unclear. So i think Background Tasks are not the right way. I even don't know how to Trigger them every Minute. Do you have an idea how i can do this or is it not possible?

    Thank you
    Markus


    • Edited by Markus222 Monday, March 16, 2015 6:54 AM
    Monday, March 16, 2015 6:53 AM
  • Hi Markus,

    For your question one: Yes, when user manually switch to another app or desktop, suspend event is called.

    For your second question: Baskground task is the only choice, besides Windows Store App are designed to run at mobile device, save power is a consideration, we should not allow app to use too much power when they are not in front, for this reason even background task has some limitations to save power. The answer is not possible for a task like you described.

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 16, 2015 1:56 PM
    Moderator