Thursday, March 5, 2009

System.Threading.ThreadStateException was unhandled (c#)

This problem occurs when you add some active control like web browser.I added web browser in some panel and tried to run the application, it says

"System.Threading.ThreadStateException was unhandled"

Solution:-

So just add [STAThread] above the main function where you instantiate the class.
e.g.(c#)
[STAThread]
static void Main()
{
Application.Run(new Parent_Form());
}


Useful Links:-

  1. http://support.microsoft.com/kb/841295
  2. http://www.gamedev.net/community/forums/topic.asp?topic_id=264874
  3. http://blogs.msdn.com/adam_nathan/archive/2003/07/18/56727.aspx

3 comments:

  1. Thank you for your information about STAThread. I had pasted something between [STAThread] and Main, and got that silly exception. Now my program works!

    -Scott D.

    ReplyDelete
  2. OMG!!! THANK YOU!! I have been working on a compiler for my own programming language.. And i would get the stupid thread error when i would try to open a dialog box.. Thank you so much.

    ReplyDelete
  3. I had [STAThread] but it does not work :(
    what should I do ?

    ReplyDelete