Getting asp.net to run in an STA?

P

Peter Strøiman

Hi.

I have a very annoying problem. I have a very complex application that has
been converted from COM/COM+ C++ to C#.
The interface for my application is proprietary xml over http implemented
previously in an ASP page, now it is in an ASPX page.

The problem is my application uses a 3rd party COM object that has been
marked as an STA component. Therefore I have to run my business logic inside
an STA (until I get rid of this COM component).

I did manage to get it to work by implementing this code in my ASPX page

Thread thread = new Thread( new ThreadStart( execute ) );

thread.ApartmentState = ApartmentState.STA;

thread.Start();

while ( thread.ThreadState != ThreadState.Stopped )

Thread.Sleep( 100 );



The problem is, the debugger doesn't like this thread-change in my aspx
page. Somethimes it hangs for a minute, sometimes Visual Studio ( ver.
2003 ) crashes.

Therefore I'd like to know if it is possible to get asp.net to run page
handling inside an STA thread ( doesn't seem like it for what I've read -
but maybe there's a hidden switch )

Thanks in advance,

Peter Strøiman
 
K

Kevin Spencer

Add an aspcompat="true" attribute to your @Page directive.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
C

Chris Jackson

In the Page directive, set the AspCompat attribute as true, and the page can
be executed on an STA.

<%@ Page AspCompat="true" ... %>
 
S

Shahar

Hi, I'm not sure but did you try that:

Thread t = new Thread(new ThreadStart(Run));
t.Start();
t.Join();

when u join the main thread wait until your thread will finish.

hope it help...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top