G
Guest
I'm currently creating an mdi application and trying to use events between
various forms within the app for communication.
I have the events working without any problem when all the forms are open
but my problem comes when a form that has subscribed to an event is closed
and the event handler is not removed.
I think I've caused myself problems with the way that I open one form from
another,
to make things easier the code below is in the Display form (showing
summary info) and it is opening a add form:
try
{
this.Cursor = Cursors.WaitCursor;
AddOrder add = new AddOrder();
add.OrderAdded += new
AddOrder.OrderAddedEventHandler(this.OrderAdded);
add.MdiParent = this.MdiParent;
add.Show();
}
catch (Exception)
{
throw;
}
finally
{
this.Cursor = Cursors.Arrow;
}
Since I don't keep a reference to the AddOrder form that I added the handler
too when I close the Display form that originally created the AddOrder form
I am unable to remove the handler and an error is occuring when I raise an
event in the AddOrder form.
Any ideas of a good way to deal with removal of event handlers in this
situation or not raising the event?
various forms within the app for communication.
I have the events working without any problem when all the forms are open
but my problem comes when a form that has subscribed to an event is closed
and the event handler is not removed.
I think I've caused myself problems with the way that I open one form from
another,
to make things easier the code below is in the Display form (showing
summary info) and it is opening a add form:
try
{
this.Cursor = Cursors.WaitCursor;
AddOrder add = new AddOrder();
add.OrderAdded += new
AddOrder.OrderAddedEventHandler(this.OrderAdded);
add.MdiParent = this.MdiParent;
add.Show();
}
catch (Exception)
{
throw;
}
finally
{
this.Cursor = Cursors.Arrow;
}
Since I don't keep a reference to the AddOrder form that I added the handler
too when I close the Display form that originally created the AddOrder form
I am unable to remove the handler and an error is occuring when I raise an
event in the AddOrder form.
Any ideas of a good way to deal with removal of event handlers in this
situation or not raising the event?