ActiveX control in new thread goes slow

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Martin Baker

    ActiveX control in new thread goes slow

    I have an activeX control which I am calling from a C# program, this works
    fine.

    I now want to call the activeX control from a seperate thread, this works
    but is very slow. This is far too slow to work properly, can anyone suggest
    how I can fix this?

    The program is not doing anything else while the thread is running, the idea
    is that the thread will be running continously in a loop to animate the
    activeX control. However it runs slow from the start (only when in a
    seperate thread) even in its first time through the loop.

    I have tried setting the ApartmentState to single threaded or multi threaded
    but this make no difference:
    Thread t = new Thread (new ThreadStart(a.w ork));
    // t.ApartmentStat e = ApartmentState. STA; // control is single threaded
    t.ApartmentStat e = ApartmentState. MTA; // control is multi threaded

    I have tried setting the priority to Lowest, Normal or Highest but this make
    no difference either:
    //t.Priority=Syst em.Threading.Th readPriority.Lo west;
    //t.Priority=Syst em.Threading.Th readPriority.No rmal;
    t.Priority=Syst em.Threading.Th readPriority.Hi ghest;

    Information and code for the activeX control I am using is here:

    Specific/createATL/

    I would appeciate and ideas I can try to fix this, thanks,

    Martin



  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: ActiveX control in new thread goes slow

    Martin,

    I suspect that the code in the thread is the culprit, not how you are
    setting the thread up.

    Can you show the code in the work method on the instance of a?

    --
    - Nicholas Paldino [.NET/C# MVP]
    - nicholas.paldin o@exisconsultin g.com

    "Martin Baker" <bakerm@btinter net.com> wrote in message
    news:bjk83k$648 $1@titan.btinte rnet.com...[color=blue]
    > I have an activeX control which I am calling from a C# program, this works
    > fine.
    >
    > I now want to call the activeX control from a seperate thread, this works
    > but is very slow. This is far too slow to work properly, can anyone[/color]
    suggest[color=blue]
    > how I can fix this?
    >
    > The program is not doing anything else while the thread is running, the[/color]
    idea[color=blue]
    > is that the thread will be running continously in a loop to animate the
    > activeX control. However it runs slow from the start (only when in a
    > seperate thread) even in its first time through the loop.
    >
    > I have tried setting the ApartmentState to single threaded or multi[/color]
    threaded[color=blue]
    > but this make no difference:
    > Thread t = new Thread (new ThreadStart(a.w ork));
    > // t.ApartmentStat e = ApartmentState. STA; // control is single threaded
    > t.ApartmentStat e = ApartmentState. MTA; // control is multi threaded
    >
    > I have tried setting the priority to Lowest, Normal or Highest but this[/color]
    make[color=blue]
    > no difference either:
    > //t.Priority=Syst em.Threading.Th readPriority.Lo west;
    > //t.Priority=Syst em.Threading.Th readPriority.No rmal;
    > t.Priority=Syst em.Threading.Th readPriority.Hi ghest;
    >
    > Information and code for the activeX control I am using is here:
    >[/color]
    http://www.euclideanspace.com/mjbWor...geSpecific/net[color=blue]
    > Specific/createATL/
    >
    > I would appeciate and ideas I can try to fix this, thanks,
    >
    > Martin
    >
    >
    >[/color]


    Comment

    • Martin Baker

      #3
      Re: ActiveX control in new thread goes slow

      Nicholas,
      [color=blue]
      > Martin,
      >
      > I suspect that the code in the thread is the culprit, not how you are
      > setting the thread up.
      >
      > Can you show the code in the work method on the instance of a?[/color]

      It is run from the startAnimation( ) method below.
      In order to save your time I have tried to extract the essence here,

      namespace mjbWorld {
      class animationLoop{
      public delegate void Start (object o);
      private class Args{
      public object o;
      public Start s;
      public void work(){
      s(o);
      }
      }

      public static Thread CreateThread (Start s, Object arg){
      Args a = new Args();
      a.o = arg;
      a.s = s;
      Thread t = new Thread (new ThreadStart(a.w ork));
      t.ApartmentStat e = ApartmentState. STA; // control is single
      threaded
      // t.ApartmentStat e = ApartmentState. MTA; // control is multi
      threaded
      return t;
      }
      }
      }

      this is then run from here:

      public void startAnimation( ){
      if(animationThr ead==null) animationThread =
      animationLoop.C reateThread(new animationLoop.S tart(this.runAn imation),4);
      animationThread .Start();
      vc3d.root.timel ine((int)(nodeB ean.timelineCom mand.TIMELINE_S TART));
      }

      which runs this:

      public void runAnimation(ob ject o) {
      bool running=true;
      if(animationThr ead!=null)
      animationThread .Priority=Syste m.Threading.Thr eadPriority.Low est; // I have
      tried Normal and Highest, no difference.
      do {
      vc3d.root.step( 0,0);
      if (eventNotifyCha nged != null) eventNotifyChan ged(null,new
      mjbEventArgs(0) );
      } while(running);
      }

      The eventNotifyChan ged method goes down through the scenegraph which
      consists of many nodes, and these nodes call methods in the activeX control.
      The activeX control is a very thin wrapper for OpenGL, which is written in
      C++ and consists of a number of very simple methods like this:

      STDMETHODIMP CmjboglCtl::mgl Vertex3d(DOUBLE x, DOUBLE y, DOUBLE z) {
      glVertex3d(x,y, z);
      return S_OK;
      }

      These methods seem to take a very long time to return, but only when called
      from the thread.

      Thank you for taking the time to look at this,

      Martin









      Comment

      Working...