Re: Service hangs when accessing ActiveX control




"Lucvdv" <replace_name@xxxxxxxx> wrote in message
news:enkfi11c4mjqlbi6goqisnmoe204hoch05@xxxxxxxxxx
> On Tue, 13 Sep 2005 20:31:59 +0200, "Willy Denoyette [MVP]"
> <willy.denoyette@xxxxxxxxxx> wrote:
>
>> So what you should do is create the from and the control's instance from
>> an
>> (the same) STA thread, but again, this is not something I strongly advise
>> against.
>
> Thanks. I suppose there's a "not" too many there?
>
Yep.

>
> But it doesn't even work: the form is created in the constructor of the
> service class, which is instantiated from a sub Main with <STAThread>
> attribute.
> The form is used only as a container for the control.
>

The STAThread attribute is ignored on Main in a service, Service threads run
in an MTA by default, if this is not what you want, you have to create your
own STA thread.

> Just to see if there's a difference I changed it into <MTAThread>.
> That causes a ThreadStateException when the service is started, so it's
> not
> like the <STAThread> was ignored (which it would be if there was no COM
> interop).
>
Sure there is no difference because ... see above.

>
> So I guess I'll have to port the control's code to a managed dll.
> I've already had to do that with another piece of code in another
> application, but this time it doesn't look as if it will be simple, and
> time is pressing :(

Won't help you, Controls in .NET are UI elements and have the (almost) same
requirements as AX controls.

Willy.



.



Relevant Pages

  • Re: STAThread vs non STAThread framework
    ... > bothered to put the STAThread attribute on them. ... A couple of the Windows Forms controls are simple wrappers around ActiveX ... initialize the thread to enter the MTA whenever you call into COM for the ... that the v2 SP1 CLR initializes the thread to enter the MTA (if not marked ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: STAThread vs non STAThread framework
    ... bothered to put the STAThread attribute on them. ... A couple of the Windows Forms controls are simple wrappers around ActiveX ... Such controls need a *pumping* STA thread to run on. ... initialize the thread to enter the MTA whenever you call into COM for the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: STAThread vs non STAThread framework
    ... A couple of the Windows Forms controls are simple wrappers around ActiveX COM controls, notably all the "Dialog Controls" are AX control wrappers, one of them being the OpenFileDialog as used by the OP. ... Now, if you don't initialize your UI thread to enter an STA, the CLR will initialize the thread to enter the MTA whenever you call into COM for the first time, that is when you create an instance of say OpenFileDialog. ... STA thread created by COM hosting the FileDialog AX control. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Service hangs when accessing ActiveX control
    ... > in an MTA by default, if this is not what you want, you have to create your ... Not specifying any attribute or specifying it as STA results in the same ... service and the default is STAThread. ... > requirements as AX controls. ...
    (microsoft.public.dotnet.framework.interop)
  • Re: Service hangs when accessing ActiveX control
    ... > STA thread, but again, this is not something I strongly advise ... service class, which is instantiated from a sub Main with ... like the <STAThread> was ignored (which it would be if there was no COM ... So I guess I'll have to port the control's code to a managed dll. ...
    (microsoft.public.dotnet.framework.interop)