Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / October 2004

Tip: Looking for answers? Try searching our database.

Thread Exception disposes Form Object

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jack Wright - 12 Oct 2004 12:57 GMT
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
Jon Skeet [C# MVP] - 12 Oct 2004 13:16 GMT
>    I am creating my startup Form in a new thread the following way...

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.