I have a below code in which
ConcurrentBag<string> AdminSites = new ConcurrentBag<string>();
AdminSites.AddRangeCustom(OrganizationNavigatorHolder.Instance.GetElementIDList(filter));
ancestorsForAdminSite = new ConcurrentBag<string>();
string currentElementsAdminSite = AdminSites.ElementAtOrDefault(AdminSites.Count - 1);
ancestorsForAdminSite.AddRangeCustom(AdminSites.Where(a => a != currentElementsAdminSite).ToList());
I want to ensure only one thread execute the above code and rest of the threads wait as i am reading Adminsiteslist to fetch currentid.