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?
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 });
}
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:
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:
And the calling code:
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.)
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
Thank you Alex, I'll look into that! :)
You are welcome, Ulf, please, share your experience with us.
Thanks,
Alex
Thank you, again, Alex!
Refacotored (refactorized?) the code to a generic method, and call this fron the "GetAll" methods.
//Ulf
You are welcome, Ulf
Thanks for code sharing.
Have a nice day,
Alex
is working on a reply...