I'm working on a game in XNA, which has an inbuilt level editor. To facilitate this I want use the FileOpenDialog from Winforms. I followed the instructions as per this answer. This involves setting the [STAThread] attribute on my Program class.

Does using STAThread have any negative implications? Meaning will it cause worse performance or limit me in some way?


The STAThread attribute is used to indicate to COM that the application should use a single-threaded apartment (STA). This only affects COM objects, and is only required as certain dialogs that use COM (such as the FileOpenDialog) need the the correct threading model to be specified.

To my knowledge very little (if any) game development will make use of COM with the exception of Windows Forms dialogs and so this is won't have any impact, its simply required for those dialogs.

If you do make use of COM objects then you may want to look into COM threading models to fully understand the implication of this setting, however the short version is that in a STA all COM methods will be run on a single thread (the UI thread in this case) even if it was invoked on another thread.

Update: DirectX is available as a set of COM objects, however I'm not sure what threading model they require.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.