Microsoft Surface: Where to define methods that have only be called during startup?
I have some methods, that should only be called during startup of the application. For now, I placed the methods in OnApplicationActivated:
private void OnApplicationActivate开发者_开发问答d(object sender, EventArgs e)
{
Sound.loadSounds();
GetLocalProjects();
GetProjects();
}
But OnApplicationActivated isalso called, if the application was in the "pause" state (the shell is displayed) and is reactived. How can I avoid this? I want to call these methods only during startup.
I don't know anything about Microsoft Surface so I can't tell you if there are some other event that could be hooked up, but wouldn't an easy fix be to use a boolean instance variable to check whether initialization has been done or not?
bool _isInitialized = false;
private void OnApplicationActivated(object sender, EventArgs e) {
if( !_isInitialized ){
Sound.loadSounds();
GetLocalProjects();
GetProjects();
_isInitialized = true;
}
}
boolean startup = true;
private void OnApplicationActivated(object sender, EventArgs e)
{
If (startup)
{
Sound.loadSounds();
GetLocalProjects();
GetProjects();
startup = false;
}
}
The Best fastest solution i could come up with
How would you do this for a non-Surface application? Override OnInitialized in your main window.
精彩评论