J
Javier Bertran
Hi all,
I have an ActiveX control developed in Visual C++ 6.0 that I want to use in
a C# project. I want the ActiveX code to run on a separate thread, but can't
seem to get it to work. If for example my ActiveX member has an infinite
loop, the .NET app gives all processing to the ActiveX and never returns,
not even to redraw the window. Here is what I tried (in a nutshell):
VC++ 6.0 OCX code:
void CMyAXControlCtrl::Loop()
{
while(1) {} // infinite loop
}
C# application code:
private void MyThreadTask()
{
axMyAXControl1.Loop(); // calls the ActiveX infinite loop
function
}
private void foo()
{
threadAX = new Thread(new ThreadStart(this.MyThreadTask));
threadAX.Start();
}
Note that my Main function in C# is declared with [STAThread], if I declare
it as [MTAThread] I get an unhandled exception of type
'System.Threading.ThreadStateException' in system.windows.forms.dll (Could
not instantiate ActiveX control because the current thread is not in a
single-threaded apartment.)
Of course if I do not use an AX control and have the equivalent code in my
C# project, the threading works fine (just made sure!!!):
private void MyThreadTask()
{
// axMyAXControl1.Loop(); // calls the ActiveX infinite loop
function
while (true) {}
}
private void foo()
{
threadAX = new Thread(new ThreadStart(this.MyThreadTask));
threadAX.Start();
}
Thanks in advance,
Javier Bertran
I have an ActiveX control developed in Visual C++ 6.0 that I want to use in
a C# project. I want the ActiveX code to run on a separate thread, but can't
seem to get it to work. If for example my ActiveX member has an infinite
loop, the .NET app gives all processing to the ActiveX and never returns,
not even to redraw the window. Here is what I tried (in a nutshell):
VC++ 6.0 OCX code:
void CMyAXControlCtrl::Loop()
{
while(1) {} // infinite loop
}
C# application code:
private void MyThreadTask()
{
axMyAXControl1.Loop(); // calls the ActiveX infinite loop
function
}
private void foo()
{
threadAX = new Thread(new ThreadStart(this.MyThreadTask));
threadAX.Start();
}
Note that my Main function in C# is declared with [STAThread], if I declare
it as [MTAThread] I get an unhandled exception of type
'System.Threading.ThreadStateException' in system.windows.forms.dll (Could
not instantiate ActiveX control because the current thread is not in a
single-threaded apartment.)
Of course if I do not use an AX control and have the equivalent code in my
C# project, the threading works fine (just made sure!!!):
private void MyThreadTask()
{
// axMyAXControl1.Loop(); // calls the ActiveX infinite loop
function
while (true) {}
}
private void foo()
{
threadAX = new Thread(new ThreadStart(this.MyThreadTask));
threadAX.Start();
}
Thanks in advance,
Javier Bertran