IConnectionPoint.Unadvise error

B

Bart

Hi,

I have a problem when I try to close my Win application.
I have done something like that:
1. I have a StartForm that is the form I put in the main:
Application.Start(new StartForm());
2. Inside this form I make a thread that creates another form. The thread is
necessary to let the application faster. This Form is called Form1. When the
thread has instanced Form1 appears a button to let Form1 showing.
3. When Form1 is showed I do: StartForm.Hide();
4. Everything works properly in Form1.
5. When I close Form1 I would like to close everything, so I put in
Form1_Closed the method Application.Exit()

......but when I close Form1 I receive three times these unhandled
exceptions - where is my mistake?:

An unhandled exception of type 'System.NullReferenceException' occurred in
system.windows.forms.dll
Additional information: Object reference not set to an instance of an
object.

Unhandled Exception: System.NullReferenceException: Object reference not set
to an instance of an object.
at System.Windows.Forms.IConnectionPoint.Unadvise(Int32 cookie)
at System.Windows.Forms.ConnectionPointCookie.Disconnect()
at System.Windows.Forms.ConnectionPointCookie.Finalize()An unhandled
exception of type 'System.NullReferenceException' occurred in
system.windows.forms.dll
Additional information: Object reference not set to an instance of an
object.

Unhandled Exception: System.NullReferenceException: Object reference not set
to an instance of an object.
at System.Windows.Forms.IConnectionPoint.Unadvise(Int32 cookie)
at System.Windows.Forms.ConnectionPointCookie.Disconnect()
at System.Windows.Forms.ConnectionPointCookie.Finalize()An unhandled
exception of type 'System.NullReferenceException' occurred in
system.windows.forms.dll
Additional information: Object reference not set to an instance of an
object.

Unhandled Exception: System.NullReferenceException: Object reference not set
to an instance of an object.
at System.Windows.Forms.IConnectionPoint.Unadvise(Int32 cookie)
at System.Windows.Forms.ConnectionPointCookie.Disconnect()
at System.Windows.Forms.OleInterfaces.StopEvents()
at System.Windows.Forms.OleInterfaces.Finalize()The program '[1892]
TestApplication.exe' has exited with code 0 (0x0).

thank you

Bart
 
B

Bart

Tim Wallace said:
Do you kill the worker thread before closing the application?

I would like to do, but I don't know how.
Actually I read that a thread should die "by itself".
If I force it by using mythread.Abort(); I receive anyway an exception.

Bart
 

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