ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
NSNicolai Søndergaard26/01/2010

Hi,

I'm working on a tool for our Solidworks users, to verify various properties on an assembly, and then importing it into our PDM system.

I have made an add-in, that loads a winform, inside SW, and then loads all the components into a list.

If i do this on the main UI thread, it happens in 0 seconds. If i create a backgroundworker thread, and run the EXACT same function, it takes 1+ minutes.

Do i need to something, to utilize multiple threads in SW, or is my problem elsewhere?

Just in case, here is the function i run

        private void GetParts()         {             DateTime Starttime = DateTime.Now;             List<clsComponent> lstComps = new List<clsComponent>();             List<clsComponent> lstCompsSuppressed = new List<clsComponent>();             List<string> lstCompNames = new List<string>();             ModelDoc2 swPartModel = null;             swPartModel = (ModelDoc2)iSwApp.ActiveDoc;             if (swPartModel == null)                 return;             if (swPartModel.GetType() == 2)             {                 AssemblyDoc AssyDoc = (AssemblyDoc)swPartModel;                 object[] oComponents = (object[])AssyDoc.GetComponents(false);                 int iMax = oComponents.Length;                 int iCount = 0;                 foreach (object oComp in oComponents)                 {                     clsComponent NewComp = new clsComponent(oComp, hshTCProperties);                     if (!lstCompNames.Contains(NewComp.FileNameWithExt))                     {                         lstCompNames.Add(NewComp.FileNameWithExt);                         lstComps.Add(NewComp);                     }                     if (NewComp.isSuppresed)                     {                         lstCompsSuppressed.Add(NewComp);                     }                     iCount++;                 }             }             SuppressedComponents = lstCompsSuppressed.ToArray();             AssemblyComponents = lstComps.ToArray();             DateTime Endtime = DateTime.Now;             TimeSpan TotalTime = Endtime.Subtract(Starttime);             MessageBox.Show("TotalRunTime: " + TotalTime.TotalMinutes.ToString("00") + ":" +                 TotalTime.Seconds.ToString("00"));                         FillListView(AssemblyComponents);         }