问题
I am implementing a windows store application for windows rt. It uses a backgroundtask to update its tile. I want to be able to configure the backgroundtask and the application to use the same urls when performing work, so i want to use a unified or centralized configuration. Right now i am using some *.resw files to configure certain aspects in my Windows Store application. How can i pass this configuration to the background task?
回答1:
The easiest way is using ApplicationData.Current.LocalSettings
Here is an example of wrapper which I use in my app:
public class SettingsService
{
private readonly ApplicationDataContainer _container;
public SettingsService()
{
var localSettings = ApplicationData.Current.LocalSettings;
if (!localSettings.Containers.ContainsKey("AppSettings"))
{
_container = localSettings.CreateContainer("AppSettings", ApplicationDataCreateDisposition.Always);
}
else
{
_container = localSettings.Containers["AppSettings"];
}
}
private T GetValue<T>(string key, T @default)
{
if (_container.Values.ContainsKey(key))
{
return (T)_container.Values[key];
}
return @default;
}
private void SetValue(string key, object value)
{
if (!_container.Values.ContainsKey(key))
{
_container.Values.Add(key, value);
}
else
{
_container.Values[key] = value;
}
}
//Any setting
public bool IsFirstLaunch
{
get { return GetValue("IsFirstLaunch", true); }
set { SetValue("IsFirstLaunch", value); }
}
}
回答2:
Weirdly enough i answered my own question in a different thread
Using app resw file from background task
来源:https://stackoverflow.com/questions/13363214/pass-parameters-to-ibackgroundtask