4 Replies Latest reply on Sep 1, 2011 9:49 AM by volker.hetzer

    Multi threading with Expedition API?

    volker.hetzer

      Hi!

      How does the Expedition API behave when API calls come in from a multi threaded client?

       

      We are doing an AddIn with a Gui and that Gui isn't supposed to freeze duting API operations. The standard way for windows Forms Applications (a COM registered dll in our case) is to have the Gui in the main thread and to run the operations in a separate (background) thread. In that case the Expedition API would sit on a blocking API call (the one that does the Gui and pumps the windows message queue) and receive API calls from another thread of the same process.

      • Would that reliably work with the Expedition API?
      • Additionally
        • How much locking goes on in the Expedition API? When one thread creates a user layer text and the other scans through the user layer text collection, how much trouble can we get into?
        • Can two threads access the API concurrently in a readonly way?
        • Are method calls like Object.IsValid() thread safe?
        • What about iterating through collections?

       

      Logs of Greetings!

      Volker

        • 1. Re: Multi threading with Expedition API?
          jeremy_parker

          First off, what language are you using?

           

          It really depends on what extent you want to do the threading. In ALE, I create classes(.dlls) that do all my work for me. I then create a background thread for that class and wait for it to finish. It's not the most efficent but it works.

           

          You can't, however, call multiple instances of, let's say, cell editor...even if you are calling a different partition. I have tried that before, even creating a new object of that class, and it still would not let me run two different instance to speed up the process.

           

          Here is an example of how I do it in VB.

           

          Create a class, then create an instance of that class.

           

          Dim trdWork as thread

           

          trdWork = new Thread(Address of clWork.ThingIWantTodo)

          trdWork.isbackground = true

          trdWork.start()

           

          trdWork.Join

           

          From here the thread is complete and you can put code in to pull the data from that class isntances

           

          Dim sResults as string = clWork.sResults

           

          Here is a great link that would help with treading:

           

          http://www.java2s.com/Tutorial/VB/0420__Thread/0020__Thread-Create.htm

          • 2. Re: Multi threading with Expedition API?
            volker.hetzer

            Hi!

            We are using c#.

             

            That is, it starts in VBScript and goes like this:

            • (drag the VBScript onto the Expedition PCB document)
            • set DllLoader=createobject("fsc_mgcentry.fsc_mgcentry") ' this is our .NET dll loader.
            • set AddOnObject=DllLoader.LoadAssembly("...\xxx.dll") ' this loads the (properly attributed c#-)assembly from a network share and creates the default object.
            • (attaching events and other stuff)
            • ...
            • AddOnObject.methodcall(Application.ActiveDocument)

             

            Now, "methodcall()" displays the Gui, I click around, press the "runActions"-button and then Expedition API calls happen. Only, the Gui should display progress, react to clicks and generally be alive.

             

            Currently we do a very cumbersome procedure of the Gui sitting on a separate thread and funneling back predefined calls to the main thread. This is what I'd like to get rid of. In fact, I'd like to use the Windows Forms background worker control for the API stuff.

             

            In addition, of course, we do have machines with 8 CPUs and it'd be great if we could utilize them for CPU intensive stuff like mask engine operations. For this it's necessary to know how the API reacts to several API calls happen all at once. Like, I "pick" on each quarter of a PCB and process them independently. Then overlapping Components will be queried from two threads.

             

            As for your example, does it work with more than one worker thread too?

            • 3. Re: Multi threading with Expedition API?
              john_dube

              All API calls must be done on the main UI thread, you will get an exception if you attempt to call a method from a worker thread.

               

              In your main thread, build up a data structure with information gathered through the API, and create a thread to do the time-consuming work with those data structures.

               

              If you need to make any changes to the document object, your addin can queue up the necessary data structures, and process those in the next OnIdle event.

               

              John

              • 4. Re: Multi threading with Expedition API?
                volker.hetzer

                That's a pity but thanks a lot for confirming it.

                 

                We'll cope.

                 

                Lots of Greetings!

                Volker