Try our conversational search powered by Generative AI!

Exits function in the middle of foreach

Vote:
 

I've written a piece of code that loops a page list and adds some info of each page to a dataset. All works well so far but then I added a function to also add the url of the files located in the page folder of that each page and then it all started acting a bit weird. No matter what I wrote in the loop there was no result so I added a break point before calling the function (below) to see what happened. If I step through all I see is the steps going from the GetImages(); to the first line in the function (VirtualPathUnifiedProvider provider = ...) and then back to the GetImages();. No error thrown, no stepping through the lines before the call of GetImages(); but all the results from the lines before it are in the DataSet as expected.

Any idea what might be going on here? I'm really confused about this.

private void GetImages(int id)
        {
            try
            {
                VirtualPathUnifiedProvider provider = (VirtualPathUnifiedProvider)VirtualPathHandler.GetProvider("SitePageFiles");

                string pageFolderName = VirtualPathUtility.AppendTrailingSlash(id.ToString()) ?? string.Empty;
                string path = VirtualPathUtilityEx.Combine(provider.VirtualPathRoot, pageFolderName) ?? string.Empty;

                if (provider.DirectoryExists(path))
                {
                    UnifiedDirectory vdir = (UnifiedDirectory)provider.GetDirectory(path);

                    foreach (UnifiedFile file in vdir.Files)
                    {
                        ...
                    }
                }
            }

            catch(Exception ex)
            {
                
            }
        }



#117238
Feb 14, 2015 21:19
Vote:
 

Sounds like you're hitting the code from different threads. Compare System.Threading.Thread.CurrentThread.ManagedThreadId between the two. Are there multiple (possibly simultaneous) calls to GetImages triggered from the same request? There are ways to cope with this situation using conditional breakpoints, see this.

#117241
Feb 15, 2015 0:02
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.