AnsweredAssumed Answered

multi-threading in SW-addin

Question asked by 1-I322R4 on Jan 26, 2010
Latest reply on Oct 24, 2011 by Arthur Prishchepov


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)
            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))
                    if (NewComp.isSuppresed)


            SuppressedComponents = lstCompsSuppressed.ToArray();
            AssemblyComponents = lstComps.ToArray();

            DateTime Endtime = DateTime.Now;
            TimeSpan TotalTime = Endtime.Subtract(Starttime);

            MessageBox.Show("TotalRunTime: " + TotalTime.TotalMinutes.ToString("00") + ":" +