Unloading of add-in RRS feed

  • Question

  • Hi all, one question. Is there some method called from WHS when the console tab add-in (dll) is unloaded? Similar situation as Onclose for dialog. I don't mean desctructor of add-in class, but some method of calling from WHS framework. I need to clean up some thread matters that are running on the background. Many thanks for any comments!


    Thursday, August 30, 2007 8:35 PM

All replies

  • The only way a tab is removed is if the underlying file is deleted and because of that there is no way to unload a tab programmatically while the Server Console is running due to the way the assemblies containing the add-ins are loaded.
    Friday, August 31, 2007 1:57 AM
  • Many thanks for response, but I thought rather unloading in the the meaning of closing Windows Home Sever console, not deleting whole add-in dll. So, when the Windows Home Server console (i.e. dialog for this console) is closing, is there some chance to catch this event and make some clean up? Many thanks!


    Friday, August 31, 2007 12:29 PM
  • Can't you just use the close event of your form?
    Friday, August 31, 2007 4:13 PM
  • Close event only gets you half way as it's only going to be fired when you close close the form when running the Console locally on the server... because the remote client uses RDP the Console is technically always running (after it's first remote launch) so we need to also be able to detect when that user disconnects... that's available by subscribing to the SystemEvents.SessionSwitch event and checking for when the reason is SessionSwitchReason.RemoteDisconnect.


    So in C#:


    Code Snippet

    SystemEvents.SessionSwitch += new SessionSwitchEventHandler(SystemEvents_SessionSwitch);



          void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)


             if (e.Reason = SessionSwitchReason.RemoteDisconnect)


                //handle disconnect




    So between this and FormClosing you've got the 2 main graceful ways that the console can be 'closed'... a third exists where you've got the Console already running either locally on the server or remotely via RDP and then launch it on the other side... in that case the existing instance is closed/terminated and a new one is launched. As yet I haven't quite figured out a good internal way to detect that.


    It should be said though that you might want to think about redesigning your code a bit so that you do not have to do your explicit cleanup work at shutdown so as to avoid this sort of issue. Granted it's not always possible... but should be strived for.

    Sunday, September 2, 2007 4:40 PM