My appにはCycleManagerというシングルトンクラスがあります。私はこのWindowsアプリケーションの制御フロー
public sealed class CycleManager
{
public static readonly CycleManager instance = new CycleManager();
public CycleManager()
{
//ReadFromIsolatedStorage();
}
public static CycleManager Instance
{
get
{
return instance;
}
}
}
のような、この目的のために密封されたクラスを作成しているとApp.xaml.csは、私が行く必要があるかどうかを確認するためにRootFrame_Navigatingを()を使用している
public App()
{
UnhandledException += Application_UnhandledException;
InitializeComponent();
InitializePhoneApplication();
RootFrame.Navigating += new NavigatingCancelEventHandler(RootFrame_Navigating); if (System.Diagnostics.Debugger.IsAttached)
{
Application.Current.Host.Settings.EnableFrameRateCounter = true;
PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
}
}
次のコードを持っていますメインページまたはログインページに移動します。
私はインスタンスがRootFrame_Navigating(内部で呼び出されたときにCyclemanagerインスタンスが作成されることを期待していたvoid RootFrame_Navigating(object sender, NavigatingCancelEventArgs e)
{
//throw new NotImplementedException();
if (e.Uri.ToString().Contains("/RootPage.xaml") != true)
return;
CycleManager pCycMan = CycleManager.instance;
e.Cancel = true;
RootFrame.Dispatcher.BeginInvoke(delegate
{
if (pCycMan.GetPasswordEnabled())
RootFrame.Navigate(new Uri("/PasswordPage.xaml", UriKind.Relative));
else
RootFrame.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
});
}
)
しかし、デバッグは、アプリケーション()constuctor後に私への制御フローの動きをそのジュースを示しましたCycleManagerクラスを作成し、CycleManager()コンストラクタの後にRootFrame_Navigatingに移動します。 !!何か間違っているか、間違っていると私は理解していますか?
第2のことは、CycleManager pCycMan = CycleManager.instance;
の実行時です。CycleManagerの次のコードが呼び出されていると思いますが、驚くことではありません。次に、シングルトンプロパティはどのように管理されますか?または毎回新しいobjが作成されますか?
public static CycleManager Instance
{
get
{
return instance;
}
}
Alfah
' CycleManager pCycMan = CycleManager.instance; 'CycleManager.Instance'を意味しますか? – abhinav