Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7077559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:26:17+00:00 2026-05-28T06:26:17+00:00

My app has a singleton class called CycleManager. I have created a sealed class

  • 0

My app has a singleton class called CycleManager. I have created a sealed class for this purpose like this

public sealed class CycleManager
{
    public static readonly CycleManager instance = new CycleManager();

    public CycleManager()
    {
        //ReadFromIsolatedStorage();
    }

    public static CycleManager Instance
    {
        get
        {
            return instance;
        }

    }
}

And the App.xaml.cs has the following code

    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;
        }
    }

I have used the RootFrame_Navigating() to check if i need to go to the main page or the login page.

    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));
        });
    }

I had expected that the Cyclemanager instance will be created when an instance is called inside the RootFrame_Navigating()

But debugging showed me that jus after the App() constuctor , the control flow moves to the Cycle manager class and after the CycleManager() constructor it moves to the RootFrame_Navigating. !! Is there something wrong or I have understood it wrong?

Second thing is that on executing of CycleManager pCycMan = CycleManager.instance; I expected the following code in the CycleManager is being called but surprisingly it isnt. Then how does singleton property managed? or everytime a new obj is created?

    public static CycleManager Instance
    {
        get
        {
            return instance;
        }

    }

Alfah

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:26:18+00:00Added an answer on May 28, 2026 at 6:26 am

    If you look at the C# specification for static field initialization

    […] the static field initializers are executed at an
    implementation-dependent time prior to the first use of a static field
    of that class

    So the order that your breakpoints are hit is in-line with the specification, in other words static fields are initialized at some time determined by the runtime. However, the exact timing is not detailed. You should not write code that depends on the initialization order of static fields.

    Your second problem is that you are accessing the field, rather than the property instance vs. Instance. You should make your static field private.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a static class in my ASP.NET app that I use to hold
App has 4 view controllers; Menu, A, B and C, and a singleton class
1) .NET Assembly MyAssembly.dll implements a Singleton class MyClass 2) A .NET APP has
I'm writing a network app, where each Client has a Singleton ClientManager. For testing
I have an iPad app that receives data using UDP sockets. And it has
This has been driving me crazy for a few days now. I have an
I have a fairly large CRUD WinForm app that has numerous objects. Person, Enrollment,
My singleton global class has all these categeories in same class , in header
Writing a PHP app and have several classes that only have static methods (no
I have an app that has settings the user can pick before running the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.