Page 1 of 1

Create an instance AxTChart in my worker thread

Posted: Thu Jul 16, 2009 9:01 pm
by 15049316
I would like to create an instance o AxTChart inside my class (I'm working with C#), setup some plots, get an image. The problem is that this function is inside a method being executed in a worker thread and there is no Form associated with it.

When I do "new AxTChart()" I get an thread exception that says that I "cannot create an instance of the ActiveX control because the current segment is not in an STA (single-threaded apartment)".

What should I do?

Re: Create an instance AxTChart in my worker thread

Posted: Mon Jul 20, 2009 9:22 am
by Marc
Hello,

I don't have any example project setup to check this but it seems that the thread will probably need to be created as single thread.

eg.

Code: Select all

using System;
using System.Threading;
namespace testapp
{
   class Class1
   {
      static void Main(string[] args)
      {
       Thread.CurrentThread.ApartmentState = 
          ApartmentState.STA;
      }
   }
}
If that doesn't give you the results you require and you have a small sample application you can send us we'll take a look.

Regards,
Marc Meumann