Process.Start fails on separate thread

  • Thread starter Thread starter Paul E Collins
  • Start date Start date
P

Paul E Collins

I use Process.Start to open a URL in the user's browser.

When I call the function normally, it works fine. However, when I call it
from a separate thread, I get an error: "The requested section was not
present in the activation context".

The only C# newsgroup thread dealing with this error blames it on a Main
function that is missing the [STAThread] attribute - but my Main function
has this attribute.

What can I do to work around this?

P.
 
Sure, but your "separate" thread is not initialized for STA I guess.

Willy.
 
Willy Denoyette said:
your "separate" thread is not initialized for STA I guess.

Adding [STAThread] to all functions called by that thread doesn't fix the
problem. Is this what you mean by "initializing for STA"?

Any other suggestions?

P.
 
No, you have to initialize the thread by setting the ApartmentState
property, preferably before calling Thread.Start.

<code snippet>

thread = ....
thread.ApartmentState = ApartmentState.STA;
thread.Start();
....
</code snippet>
Willy.



Paul E Collins said:
Willy Denoyette said:
your "separate" thread is not initialized for STA I guess.

Adding [STAThread] to all functions called by that thread doesn't fix the
problem. Is this what you mean by "initializing for STA"?

Any other suggestions?

P.
 
Back
Top