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 1042679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:32:46+00:00 2026-05-16T15:32:46+00:00

I’m calling my custom factory that I created (PhotoServiceFactory), which is a singleton that

  • 0

I’m calling my custom factory that I created (PhotoServiceFactory), which is a singleton that allows me to get at a specific custom service type back (in this case FacebookService). FacebookService is also a singleton. In FacebookService I’ve exposed an instance of FacebookAlbumPhoto through a property. I did this because then I don’t have to have a ton of the same code over and over again creating a new instance of FacebookAlbumPhoto…I can get an instance using the FacebookService’s property.

PhotoServiceFactory service = PhotoServiceFactory.CurrentPhotoServiceFactory;
FacebookService facebookService = (FacebookService)service.GetAPIService(APIType.Facebook);

FacebookAlbumPhoto facebookPhoto = facebookService.FacebookAlbumPhoto.GetFacebookAlbumPhoto(selectedPhotoID);

So this is all set up now, I created all this and just testing it now.

What’s happening is my code is bombing out at this line:

FacebookAlbumPhoto facebookPhoto = facebookService.FacebookAlbumPhoto.GetFacebookAlbumPhoto(selectedPhotoID);

The error I get is when I try to reference the facebookService.FacebookAlbumPhoto instance:

CurrentSession = ‘_singletonInstance.CurrentSession’ threw an exception of type ‘System.Threading.ThreadAbortException’

So I don’t know if it’s because the service singleton is on one thread and then it tries to reference another singleton that’s on a completely different thread and that’s just not possible? That it’s not possible to nest singletons like this? Or could this be another issue altogether? Cause I can’t see it.

Here’s my ServiceFactory:

public class PhotoServiceFactory
{
    private static PhotoServiceFactory _singletonInstance;
    private PhotoServiceFactory(){}

    public static PhotoServiceFactory CurrentPhotoServiceFactory
    {
        get
        {
            _singletonInstance = _singletonInstance ?? (_singletonInstance = new PhotoServiceFactory());
            return _singletonInstance;
        }
    }

    public object GetAPIService(APIType apiType)
    {
        object apiService = null;
        switch (apiType)
        {
            case APIType.Facebook:
                apiService = FacebookService.CurrentService;
                break;
            // rest of code
        }

        return apiService;
    }

So the main singleton here Service has a property to get its related Session:

Here’s the FacebookServiceClass:

public class FacebookService
{
    private static FacebookService _singletonInstance;

    private FacebookService(){}

    public FacebookSession CurrentSession
    {
        get
        {
            return FacebookSession.GetCurrentSession();
        }
    }

    /// <summary>
    /// Gets the current facebook service singleton instance.
    /// </summary>
    /// <value>The current facebook service.</value>
    public static FacebookService CurrentService
    {
        get
        {
            _singletonInstance = _singletonInstance ?? (_singletonInstance = new FacebookService());
            return _singletonInstance;
        }
    }

    public FacebookAlbumPhoto FacebookAlbumPhoto
    {
        get
        {
            return new FacebookAlbumPhoto(); // create an instance automatically so we can start working with this object
        }
    }
}

Here’s the session class:

public class FacebookSession
{
    const string loginCallbackUrl = "http://localhost/PhotoUpload/FacebookOauth.aspx";

    private FacebookSession()
    {
    }

    public string UserID { get; private set; }

    public static FacebookSession GetCurrentSession()
    {
        //....bunch of other logic is here
        FacebookSession facebookSession = CreateNewSession();
        return facebookSession;
    }

    public FacebookSession CreateNewSession()
    {
        //...some code here
        FacebookSession newFacebookSession = new FacebookSession
        //... rest of code...
        return newFacebookSession;
    }
    // ... rest of code
}

UPDATED:

As requested here’s my FacebookAlbumPhoto class that I created:

    public class FacebookAlbumPhoto : FacebookPhotoBase
    {
        private FacebookSession currentSession;

        public FacebookAlbumPhoto()
        {
            currentSession = FacebookService.CurrentService.CurrentSession;             
        }

        #region Methods

        public FacebookAlbumPhoto GetFacebookAlbumPhoto(string photoID)
        {
            ...more code
             FacebookPhotoRequest request = new FacebookPhotoRequest(currentSession.UserID, photoID);
            ...more code

            FacebookAlbumPhoto facebookPhoto = ParseFacebookPhoto(json);

            return facebookPhoto;
        }
...rest of code
}
  • 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-16T15:32:47+00:00Added an answer on May 16, 2026 at 3:32 pm

    Two things. First, remember to read over Skeet’s catalogue of singleton implementations.
    Second, try breaking your code just before the spot where the exception occurs, and then bring up your “Exception” dialogue (ctrl-alt-e). Click the “throw” checkbox next to the CLR (second row of dialogue) and hit ok. Continue debugging your code. The results may tell you where the real problem is.

    Don’t forgot to go back to the Exception dialogue and remove that check from the check box, after you are done. 🙂

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words

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.