- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I'm learning to program a plugin for Navisworks, I started by grabbing the ModelItens from the Current Selection and doing a foreach to see each ModelItem display name and assign it to the corresponding classification accordingly to its string pattern and then paint them, but now I wanted to expand, and try to do it to the entire file that have hundreds of thousands of itens, and i got the following error:
"Managed Debugging Assistant 'ContextSwitchDeadlock' : 'The CLR has been unable to transition from COM context 0x774a81f0 to COM context 0x774a80c8 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. how to solve this error in C#?"
I believe that i'm getting this error because of the ineficiency of foreach, i tryed to use Threadding but I get other COM errors then, so I did a research and i'm thinking of using the native Search + SearchConditions for efficiency, I think that I will not have a problem with the first half of ModelItens I look as it's just those that the display name contains "/FRMW", but I don't now how to do a SearchCondition with the conditions that I used for the other half, as I used Regex to find those itens
the Regex pattern I used for the .IsMatch is : string primPattern = @"^(\/S-)\d{4}(-)\d{4}";
and here is how the DisplayName I wanted to select is "/S-2020-0245" the numbers change, but it is always /S-XXXX-XXXX where X is numbers
right now this is what I'm thinking to do to replace the foreach:
Search s = new Search();
s.Selection.SelectAll();
s.Locations = SearchLocations.DescendantsAndSelf;
/*
As the Model Itens I'm seraching are not at the botton of the tree but in the middle I think this Prune will make the code more efficient so as an exemple of the tree below I believe it will ge to the /S-2010-2212 and then it will stop going into the brance and them go to the next at the same level
*/
s.PruneBelowMatch = true;
//I believe the best way to mimic the regex will be by a list of Search Conditions with wildcards but I don't know exacly how
List<SearchCondition> oG1 = new List<SearchCondition>();
SearchCondition oGroup1_SC1 = … …
SearchCondition oGroup1_SC2 = … …
oG1.Add(oGroup1_SC1);
oG1.Add(oGroup1_SC2);
s.SearchConditions.AddGroup(oG1);
// And them repeat this process to the simpler search condition of Contains "/FRMW"
So recapping, I want to know if for what I want to do and the volumen of it the use of the Search and how I'm thinking will solve the DeadLock I'm getting, if it is really the fastest way for doing so and How to make it mimic the regex.ismatch I use in the foreach.
Solved! Go to Solution.