Dominque,
Don't do this. This is not a destructor. Rather, it is a finalizer,
and it is not called when the object goes out of scope. Rather, it is
called when the object is being reclaimed by a collection by the GC.
Also, I don't think the model you have is really a good one. Since you
are exposing the events, why not just have the views add the event handlers
themselves when they are constructed? You can pass the model to the views,
and they can decide how to hook up to it.
Your views should implement IDisposable (I imagine they do already), and
in that implementatio of Dispose, you can remove the event handler (so that
a reference to you is not kept through the delegate).
I don't know that this will solve your problem, but I think that there
is more to it. I haven't heard of any problems of delegates just being
dropped from event invocation lists...
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"Dominique" <Do*******@discussions.microsoft.com> wrote in message
news:B5**********************************@microsof t.com...
Hi Nicholas,
Thanks for your prompt reply.
RemoveView is only called once in the whole project group and that occurs
in
the MVCView destructor as follows...
~MvcView()
{
if ( DataModel != null )
DataModel.RemoveView( this );
}
I planned to make this demo public once I ironed out this last bug and
commented the code for other newbies to hopefully learn by.
The other stuff it also shows...
0. How to create an MDI application
1. How to use GDI+ for Pie Charts and Graphs
2. Double Buffering to avoid flickering
3. Type Enumeration using Relection
4. How create an ArrayList descendent
5. How to use the ArrayList descendent in a DataGrid
6. It shows how you may want to implement a simple plugin system
Dominique
"Nicholas Paldino [.NET/C# MVP]" wrote:
Dominque,
From what you have shown, it doesn't seem like you should be having
that
problem. Is there any point where you remove the delegates and it is
possible that you are removing it?
Is this all of the code?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Dominique" <Do*******@discussions.microsoft.com> wrote in message
news:B0**********************************@microsof t.com... > In order to become more familiar with the Model-View-Controller
> pattern, I
> have written a demo where each View is a plugin and the plugins are
> loaded
> at
> startup from the plugins directory. When the View's are loaded they add
> themselves to the DataModel View list...
>
> FDataModel.AddView(this);
>
> Where AddView looks like this...
> public void AddView( MvcView view )
> {
> ViewChanged += new ViewChangedHandler(view.DataModified);
> }
>
> and at the right time I invoke the event list via...
> ViewChanged(this, e);
>
> This all works fine as long as I only have 1 instance of each type of
> view.
> So in this case I have a Pie Chart View and Bar Chart view of the data
> (
> as
> well as the usual DataGrid view all as plugins ). Then the delegates
> correctly fire and everything works as advertised. The problem arises
> if I
> instantiate a second instance of say the Bar Chart. When that happens
> the
> first Bar Chart stops responding/refreshing while the second Bar Chart
> updates correctly.
>
> Can any C# pattern gurus shed some light on what I might have
> overlooked?