I want to write a Win8 app, there I use a Configuration
-class with a static
member, which is loaded once at startup and can be accessed from everywhere at runtime.
So, the main problem is, the default settings are stored within an xml file, but reading file content is asynchronous (StorageFile
), but I do not find any solution to wait, until the file is completely loaded, because it is not possible to use await
in every situation (main thread, constructors), what looks to me like a design issue.
If the file isn't read completely before the Configuration
data is accessed, there will be incorrect behaviors for this app.
here is an example code:
public class Configuration
{
// stores the only instance of this class
private Configuration instance = null;
// public access to the instance
public Configuration Current
{
get
{
if (instance == null)
{
instance = new Configuration();
}
return instance;
}
}
private Configuration()
{
// load data from file synchronously
// so it is loaded once on first access
}
}
I'm not sure, how to solve this problem, probably I need to change the design of my Configuration
-class. Any suggestions/hints would be nice.