This project is read-only.

Presenter.Dispose() Infinite Loop

Jul 31, 2008 at 2:38 PM
Hi,  I originally posted this in the Smart Client Guidance project discussion list, but figured I'd post it here too since it's referencing the contrib demo.
Link to other discussion item: http://www.codeplex.com/smartclient/Thread/View.aspx?ThreadId=32574

-------------------------------
I was trying to do the demo script from the contrib project and kept running into StackOverflowExceptions when I tried to do the "Close View Programatically" button.

I have the April 2008 release installed (with the couple of changes for VS2008 SP1 Beta listed here).  I also have the trunk release of the contrib demo app that I'm looking through.

In the code generated by the Smart Client Factory for my demo app, the Dispose() for the Presenter class is:
{code:c#}
public void Dispose() {
    if (!disposed) {
        Dispose(true);
        GC.SuppressFinalize(this);
    }
}

protected virtual void Dispose(bool disposing) {
    if (disposing) {
        if (_workItem != null) {
            if (this.View != null) {
                OnCloseView();
                _workItem.Items.Remove(this.View);
            }

            _workItem.Items.Remove(this);
        }
    }

    disposed = true;
}
{code:c#}

While the code from the trunk of contrib's demo app has the following:
{code:c#}
public void Dispose()
{
    Dispose(true);
    GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
    if (disposing)
    {
        if (_workItem != null)
            _workItem.Items.Remove(this);
    }
}
{code:c#}

What is happening is that in my code, when the Dispose(true) is called by Dispose() (because the disposed flag was not yet set) the OnCloseView() is called creating an infinite loop.  As a point of reference, the demo application view's "Close View Programatically" action is to call the view's presenter OnCloseView() function.

Is calling OnCloseView() the wrong action?  Or is there something else I should be setting/changing/calling?