Unsubscribing to static events on forms where DocumentWindowis parent

3 posts, 0 answers
  1. Chris
    Chris avatar
    9 posts
    Member since:
    Mar 2007

    Posted 07 Dec 2012 Link to this post

    I have a few global static events that some of my forms subscribe to.  The subscription happens in the Form.Load event of each form.  Those forms are added to a DocumentWindow then to the DockManager.  The subscription is great, everybody's listening fine.  Now when I close a DocumentWindow, the forms OnClosing events doesn't happen thus not unsubscribing to the static event I had wired.  So now when another form (document window) fires the static event I get an exception from the closed form where the static handler is trying to work but the form doesn't exists anymore.

    Any ideas on how to unsubscribe to static events on forms that are children to DocumentWindows once closed?

  2. Chris
    Chris avatar
    9 posts
    Member since:
    Mar 2007

    Posted 07 Dec 2012 Link to this post

    Figured out a hack.  I simply created an Interface called IStaticEventHandler and added just one method called UnsubscribeFromEvents().  The form added to the DockWindow implements this.

    Now, OnDockWindowClosing test to see if Controls[0] (the form is the only control added) of the DockWindow is of type IStaticEventHandler.  If it is set a local variable to Controls[0] as an IStaticEventHandler type then called the UnsubscribeFromEvents() method.

    That worked!!
  3. Julian Benkov
    Julian Benkov avatar
    1135 posts

    Posted 12 Dec 2012 Link to this post

    Hi Brian,

    I am glad to hear that you found a way to achieve the desired requirement.

    If you have additional questions regarding your scenario, please open a new support ticket and send me a sample project which demonstrates it. This will allow me to assist you adequately.

    Julian Benkov
    the Telerik team
    Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
Back to Top