Thread Exception disposes Form Object

J

Jack Wright

Dear All,
I am creating my startup Form in a new thread the following way...
Thread oFormThread = new Thread(new ThreadStart(AddFormInThread));
AddFormInThread
{
Application.ThreadException += new
ThreadExceptionEventHandler(OnFormThreadException);
oHiddenForm = new frmStartup(this);
oHiddenForm.Visible = false;
oHiddenForm.IsAccessible = false;
Application.Run(oHiddenForm);
}
OnFormThreadException
{
MessageBox.Show(ThreadException.Exception.ToString());
}

now if I create a Form Object x via reflection and throw an exception
in its constructor...I get the exception in
onFormThreadException...but the next time I again try to create the
Object x...I get the following exception...
Object reference not set to an instance of an object.
Stack Trace: at System.Windows.Forms.SafeNativeMethods.MessageBox(HandleRef
hWnd, String text, String caption, Int32 type)
at System.Windows.Forms.MessageBox.ShowCore(IWin32Window owner,
String text, String caption, MessageBoxButtons buttons, MessageBoxIcon
icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions
options)
at System.Windows.Forms.MessageBox.Show(String text)

I found out that my Startup is getting disposed...am I doing something
wrong here...please help...

TALIA
Many regards
Jack
 

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