i want to run my app in STA, not MTA

  • Thread starter Thread starter Tarren
  • Start date Start date
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
 
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
 
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
 
Back
Top