There are instances where on closing a Work Item View, you would also like to dispose of the footprint. Here is how it done.
Change the OnCloseView of the Presenter as follows:
#region Closing the View
/// <summary>
/// Close the view
/// </summary>
public void OnCloseView()
{
base.CloseView();
// If this presenter has created any workspaces
// be sure to remove them first.
// e.g. if (WorkItem.Workspaces.Contains(WorkSpaceName))
// WorkItem.Workspaces.Remove(WorkItem.Workspaces[WorkSpaceName]);
// Remove the View from the SmartParts Collection
this.WorkItem.SmartParts.Remove(View);
// As we are closing and re-creating this view
// several times, we need to Dispose the view.
if (View is IDisposable)
((IDisposable)View).Dispose();
}
#endregion
Open the code behind the that the presenter controls and add the following Code snippet.
#region Closing the View
void ParentForm_FormClosed(object sender, FormClosedEventArgs e)
{
_presenter.OnCloseView();
}
#endregion
Finally on the same page change the OnLoad Method so it reads:
protected override void OnLoad(EventArgs e)
{
_presenter.OnViewReady();
base.OnLoad(e);
// Capture the Form Close Event, because we want to destroy
// the view on Closing the form
this.ParentForm.FormClosed += new FormClosedEventHandler(ParentForm_FormClosed);
}
And that’s it. Each time you close the view it will be destroyed and the memory released.
My name is Allan Wissing. I operate a small Software Development company, which has been keeping me busy now for over 2 decades.
For many years I have been telling myself that I do not require a Weblog! There is no one out there that needs to know or who would want to know, what's on my mind. Weblogs about what I had last Sunday for lunch or my holiday snaps, I have considered tedious and boring.
My work however has relied heavily on the Internet and search engines and there are some really neat blog sites out there, that have helped me resolve coding problems I was encountering.
Recently however, my work has been taking me to new horizons and there has been a desire to understand and master new technologies. It came to my attention that not all the answers can be found using my favourite search engine? This was because no one had yet scripted a solution.
The next logical step I decided was to script what I thought the solution should be and what better way but via a Weblog? So here I am! Most the content will be focused on how I resolved software development issues. I welcome comments and feedback on the various subjects I might cover.
I hope some people get benefit from my perpective!