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

Setting child window location in MDI .NET

This problem occurs when you load a new child form inside the parent window while using MDI, but you are not able to set its location according to your requirement.

So there is some trick which i used.

say name of the child form is "form1"

form1.StartPosition = FormStartPosition.Manual;
form1.Location = new Point(50, 620);/* any arbitrary location*/
form1.Show();

Useful links
  1. http://www.daniweb.com/forums/thread43508.html
  2. http://bytes.com/groups/net-vb/354590-centerparent-not-working
  3. http://www.dotnet247.com/247reference/msgs/46/230816.aspx

Thanks,
Gaurav Nanda