I am trying to write a simple weather app as my first app. I have to keep the numbers of http requests as low as possible and so I am using a isolatedStorageSetting within the app to save the requested data and the date and time of the last request. Before the app start a request it looks in this file to ask when was the last request and start a new request if 120 minutes are gone. All this works perfectly within the app but now I have to implement an Scheduled Task to update the live tile and lock screen in the background. But before the background agent request the data it has to look in this file to ask for the last update and rewrite the data after request. So what I need is a file that can be used for reading and writing by the app and the background agent. I now that I need a mutex and wo on... but my questions are
what is the right kind of file or database for this case? (isolatedStorgeSettings, isolatedStorgeFile or something else)
where I have to generate this file? (within the MainPage.xaml.cs or do I need a Class Lib. Project)
how is the syntax to read and write entries in this file from the app and the background agent?
Ok I have this example now just as test to understand the hole topic step by step...
I have a Class Library "DataLib" wich contains this:
namespace DataLib { public class DataLib {
public static string DatenHolen(string DatenPacket) { IsolatedStorageFile WetterDatenDatei = IsolatedStorageFile.GetUserStoreForApplication(); try { //Create == Create OR Overwrite IsolatedStorageFileStream myStream = new IsolatedStorageFileStream("datei1.txt", System.IO.FileMode.Create, WetterDatenDatei); StreamWriter writer = new StreamWriter(myStream); writer.Write("Inhalt der Datei"); writer.Close(); } catch (Exception) { MessageBox.Show("Fehler beim Schreiben der Datei"); } try { IsolatedStorageFileStream myStream = new IsolatedStorageFileStream("datei1.txt", System.IO.FileMode.Open, WetterDatenDatei); StreamReader reader = new StreamReader(myStream); DatenPacket = reader.ReadToEnd(); reader.Close(); } catch (Exception) { MessageBox.Show("Fehler beim Auslesen der Datei"); } return DatenPacket; }
} }
I have the app itself with MainPage.xaml.cs wich have a reference to DataLib and contains this:
using DataLib;
...
txt_Test.Text = DataLib.DataLib.DatenHolen();
This line produce an error. I just wont to display the generated string within the textbox "txt_Test". Where is my misstake?
2: settings access:
Now you can access settting where you want by: