Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ulf Möllerström 70 posts 247 karma points
    Oct 08, 2016 @ 09:15
    Ulf Möllerström
    0

    Problem getting childnodes (threading issue?)

    I'm having a problem that looks like a threading issue (and of course it appeared on a Friday afternoon!)

    We have a set-up with nodes (document types without template) as properties on a member:

    • Departments ... Department
    • Places ... Place
    • Categories ... Category

    And data types as multinode treepicker (Department is single value), that points to each of the parent nodes. The member can then select his/her own setting to be displayed on their member info-page.

    The code that gets the properties is placed in two separate static classes but with instance objects of umbracohelper to get the typed content for the node:

        public static IEnumerable<Place> GetAllPlaces()
        {
            var nodeId = AppSettings["PlacesNodeId"];
            var placeAlias = AppSettings["PlaceAlias"];
            return new UmbracoHelper(UmbracoContext.Current).TypedContent(nodeId).Children
                                                                .Where(child => child.DocumentTypeAlias == placeAlias)
                                                                .Select(child => new Place { Id = child.Id, Name = child.Name });
        }
    
        public static IEnumerable<Category> GetAllCategories(){...}
    

    And the calling code:

    var allPlaces = GetAllPlaces().OrderBy(place => place.Name);
    var allCategories = GetAllCategories().OrderBy(category => category.Name);
    

    But... Yet the same code and stucture/set-up, Places return the values but not Categories!

    In the debugger/quick watch window, the childs-node states "all threads must be running" but hitting reevaluate about 4 times the childnodes are displayed.

    When moving the non working code (the one for Categories) to the partialview (for testing), it works without any problem.

    So next (first thing on Monday morning) I'll try to have the code in non static classes or refactor into one "GetProperties" class, but for future reference I'd like to know if this is at "non thread safe"-issue ore something else?

    (I'm also fairly new to Umbraco development.)

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Oct 09, 2016 @ 09:32
    Alex Skrypnyk
    100

    Hi Ulf,

    For working with data in backend it's better to use ContentService, it works directly with database and I think it hasn't such problems.

    https://our.umbraco.org/documentation/reference/management/services/contentservice

    Thanks,

    Alex

  • Ulf Möllerström 70 posts 247 karma points
    Oct 09, 2016 @ 16:34
    Ulf Möllerström
    0

    Thank you Alex, I'll look into that! :)

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Oct 09, 2016 @ 20:56
    Alex Skrypnyk
    0

    You are welcome, Ulf, please, share your experience with us.

    Thanks,

    Alex

  • Ulf Möllerström 70 posts 247 karma points
    Oct 10, 2016 @ 08:54
    Ulf Möllerström
    1

    Thank you, again, Alex!

    Refacotored (refactorized?) the code to a generic method, and call this fron the "GetAll" methods.

    public static IEnumerable<T> ChildNodesAsSelectOptions<T>(int nodeId) where T : ISelectOption, new()
    {
        var childNodes = ApplicationContext.Current.Services.ContentService.GetChildren(nodeId);
        return childNodes.Select(child => new T { Id = child.Id, Name = child.Name });
    }
    

    //Ulf

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Oct 10, 2016 @ 13:11
    Alex Skrypnyk
    1

    You are welcome, Ulf

    Thanks for code sharing.

    Have a nice day,

    Alex

Please Sign in or register to post replies

Write your reply to:

Draft