简体   繁体   中英

wp8 PeriodicTask and persisted storage

I have a PeriodicTask that updates a tile for my phone app and saves the information to persisted storage.

This works fine until the list gets to around a size of 11 or 12.

The objects that I save is a poco object with about 5 members. I basiclly get data, save data and create tile (not shown).

so

//get data
var newData = GetPocoFromWeb();
base.Add(newData); 

the base class

     public abstract class DataFetcher<T> where T : IDataCarrier, new()
        {
            protected readonly IPersist<List<T>> Persist;
            protected DataFetcher(IPersist<List<T>> persist)
            {
                Persist = persist;
            }

            protected void Add(T item)
            {
                var items = Persist.Load();
                items.Add(item);
                Persist.Save(items);
            }
        }

The persist class

public class Persist<T> : IPersist<T>
    {
        private readonly string _identifier;

        public Persist(string identifier)
        {
            _identifier = identifier;
        }

        public virtual T Load()
        {
            if (IsolatedStorageSettings.ApplicationSettings.Contains(_identifier))
            {
                return (T)IsolatedStorageSettings.ApplicationSettings[_identifier];
            }

            return default(T);
        }

        public virtual void Save(T item)
        {
            IsolatedStorageSettings.ApplicationSettings[_identifier] = item;
            IsolatedStorageSettings.ApplicationSettings.Save();
        }  

    }

Am I perhaps using wrong storage? 11 items in a list isn't really that many.

Update: When I load the list and add to it using the application (not through the periodicTask) i can easily save several hundred items.

I don't get any error when running in emulator, it just works till the list has around 11 items and then stops working.

You don't go into much detail into what error you are getting (if any), so it's difficult to say.

Having said that, here's a few things that come to mind:

  • If you call NotifyComplete() before the asynchronous call completes , you may be being shut down before you have the chance
  • Background tasks only have 6mb of memory (12mb on WP8). If you go over it your process will be terminated
  • Background tasks only have 25 seconds or so to execute. If you continue past this your process will be terminated.
  • Don't use the IsolatedStorageSettings class to share state between processes
  • You should be using a Mutex to protect process-process access to your storage.

What exactly is the problem you're experiencing? Using IsolatedStorageSettings shouldn't restrict the size of the list you're able to persist.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM