i want to run my app in STA, not MTA

T

Tarren

Hi:

How would I go about making sure my C# 2.0 app runs under STA, not MTA? Do
I add something in the Main method?

Thanks
 
D

Dan Manges

Tarren said:
Hi:

How would I go about making sure my C# 2.0 app runs under STA, not MTA? Do
I add something in the Main method?

Thanks

You just need to use the STAThread attribute.

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

If you're using a separate thread, the System.Threading.Thread class has
a SetApartmentState method.

Dan Manges
 
T

Tarren

That is so easy it is almost annoying. :)

Thanks.


Dan Manges said:
Tarren said:
Hi:

How would I go about making sure my C# 2.0 app runs under STA, not MTA?
Do I add something in the Main method?

Thanks

You just need to use the STAThread attribute.

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

If you're using a separate thread, the System.Threading.Thread class has a
SetApartmentState method.

Dan Manges
 

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

Top