browse: forums | FAQ
Connecting Tech Pros Worldwide

Hey there! Do you need Visual Basic .NET help?

Get answers from our community of Visual Basic .NET experts on BYTES! It's free.

Temporarily switch to STA threading - how???

Peter Row
Guest
 
Posts: n/a
#1: Nov 20 '05
Hi,

I think I am having some threading issues in a project I am porting from VB6
webclass to VB.NET.
Therefore I would like to temporarily set the threading mode to STA to get
around it until I have
fully ported and tested all code.

I have class that implement IHttpFactory, thus I have a GetHandler method.
However if I try to use the [STAThread] directive, like this:

Public Class MyFactory Implements IHttpHandler

[STAThread] Public Overridable Function GetHandler( ..... )

.... I then get the error that I haven't implemented GetHandler.

If as the first line of my GetHandler implementation I say:

CurrentThread.ApartmentState = CurrentThread.AppartmentState.STA

Then it does not change the threading model used it stays on MTA.

Anybody have any ideas on how I might achieve this?

Regards,
Peter





Peter Row
Guest
 
Posts: n/a
#2: Nov 20 '05

re: Temporarily switch to STA threading - how???


Hi,

It's okay I found another suitable solution.
I used a SyncLock which is adequate for this temporary hack whilst porting.

Regards,
Peter
"Peter Row" <peter.row@oxfordcc.co.uk> wrote in message
news:OdrsIGKwDHA.1060@TK2MSFTNGP12.phx.gbl...[color=blue]
> Hi,
>
> I think I am having some threading issues in a project I am porting from[/color]
VB6[color=blue]
> webclass to VB.NET.
> Therefore I would like to temporarily set the threading mode to STA to get
> around it until I have
> fully ported and tested all code.
>
> I have class that implement IHttpFactory, thus I have a GetHandler method.
> However if I try to use the [STAThread] directive, like this:
>
> Public Class MyFactory Implements IHttpHandler
>
> [STAThread] Public Overridable Function GetHandler( ..... )
>
> ... I then get the error that I haven't implemented GetHandler.
>
> If as the first line of my GetHandler implementation I say:
>
> CurrentThread.ApartmentState = CurrentThread.AppartmentState.STA
>
> Then it does not change the threading model used it stays on MTA.
>
> Anybody have any ideas on how I might achieve this?
>
> Regards,
> Peter
>
>[/color]


Rob Teixeira [MVP]
Guest
 
Posts: n/a
#3: Nov 20 '05

re: Temporarily switch to STA threading - how???


I was going to say, you really can't switch back and forth from STA to
MTA/free-threading.
Part of the reason is that under the covers the system will at some points
likely call CoInitialize, and you can't initialize COM in the same process
with different threading models.

-Rob Teixeira [MVP]

"Peter Row" <peter.row@oxfordcc.co.uk> wrote in message
news:uF0%23ixKwDHA.3220@tk2msftngp13.phx.gbl...[color=blue]
> Hi,
>
> It's okay I found another suitable solution.
> I used a SyncLock which is adequate for this temporary hack whilst[/color]
porting.[color=blue]
>
> Regards,
> Peter
> "Peter Row" <peter.row@oxfordcc.co.uk> wrote in message
> news:OdrsIGKwDHA.1060@TK2MSFTNGP12.phx.gbl...[color=green]
> > Hi,
> >
> > I think I am having some threading issues in a project I am porting from[/color]
> VB6[color=green]
> > webclass to VB.NET.
> > Therefore I would like to temporarily set the threading mode to STA to[/color][/color]
get[color=blue][color=green]
> > around it until I have
> > fully ported and tested all code.
> >
> > I have class that implement IHttpFactory, thus I have a GetHandler[/color][/color]
method.[color=blue][color=green]
> > However if I try to use the [STAThread] directive, like this:
> >
> > Public Class MyFactory Implements IHttpHandler
> >
> > [STAThread] Public Overridable Function GetHandler( ..... )
> >
> > ... I then get the error that I haven't implemented GetHandler.
> >
> > If as the first line of my GetHandler implementation I say:
> >
> > CurrentThread.ApartmentState = CurrentThread.AppartmentState.STA
> >
> > Then it does not change the threading model used it stays on MTA.
> >
> > Anybody have any ideas on how I might achieve this?
> >
> > Regards,
> > Peter
> >
> >[/color]
>
>[/color]


Closed Thread