Getting asp.net to run in an STA?

  • Thread starter Thread starter Peter Strøiman
  • Start date Start date
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
 
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.
 
In the Page directive, set the AspCompat attribute as true, and the page can
be executed on an STA.

<%@ Page AspCompat="true" ... %>
 
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...
 
Back
Top