By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,238 Members | 1,746 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,238 IT Pros & Developers. It's quick & easy.

ActiveX control in new thread goes slow

P: n/a
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.work));
// t.ApartmentState = ApartmentState.STA; // control is single threaded
t.ApartmentState = 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=System.Threading.ThreadPriority.Lowest;
//t.Priority=System.Threading.ThreadPriority.Normal;
t.Priority=System.Threading.ThreadPriority.Highest ;

Information and code for the activeX control I am using is here:
http://www.euclideanspace.com/mjbWor...geSpecific/net
Specific/createATL/

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

Martin

Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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]
- ni**************@exisconsulting.com

"Martin Baker" <ba****@btinternet.com> wrote in message
news:bj**********@titan.btinternet.com...
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.work));
// t.ApartmentState = ApartmentState.STA; // control is single threaded
t.ApartmentState = 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=System.Threading.ThreadPriority.Lowest;
//t.Priority=System.Threading.ThreadPriority.Normal;
t.Priority=System.Threading.ThreadPriority.Highest ;

Information and code for the activeX control I am using is here:
http://www.euclideanspace.com/mjbWor...geSpecific/net Specific/createATL/

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

Martin

Nov 15 '05 #2

P: n/a
Nicholas,
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?


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.work));
t.ApartmentState = ApartmentState.STA; // control is single
threaded
// t.ApartmentState = ApartmentState.MTA; // control is multi
threaded
return t;
}
}
}

this is then run from here:

public void startAnimation(){
if(animationThread==null) animationThread =
animationLoop.CreateThread(new animationLoop.Start(this.runAnimation),4);
animationThread.Start();
vc3d.root.timeline((int)(nodeBean.timelineCommand. TIMELINE_START));
}

which runs this:

public void runAnimation(object o) {
bool running=true;
if(animationThread!=null)
animationThread.Priority=System.Threading.ThreadPr iority.Lowest; // I have
tried Normal and Highest, no difference.
do {
vc3d.root.step(0,0);
if (eventNotifyChanged != null) eventNotifyChanged(null,new
mjbEventArgs(0));
} while(running);
}

The eventNotifyChanged 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::mglVertex3d(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



Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.