sharpshell icon indicating copy to clipboard operation
sharpshell copied to clipboard

Question: What is the lifetime instances of classes derived from, eg, SharpPropertySheet?

Open RichardSharpe opened this issue 5 years ago • 1 comments

If I have a class derived from SharpPropertySheet and the CanShowSheet method returns true, is the instance of the class valid until the whole Properties Dialog box is destroyed, or only until another pane/sheet is selected, or some other time?

I ask so I can know if I can define and use instance variables, like an open file handle so I am not continually opening and closing files.

RichardSharpe avatar Aug 31 '19 17:08 RichardSharpe

Hey @RichardSharpe, good question. I don't have any answer. I think, best if you check it out yourself. I am sure the SharpPropertySheet and others have some event, IDisposable or Destructors/Finalizers that you can use to observe the behaviour. Maybe there is a tool that can track the lifetime of an instance outside of the application? I am not sure if debugging with Visual Studio will work, but you might wanna try that, too. Maybe using System.Diagnostics.Debugger.Launch() works? Maybe you can check the Marshaller Count of the COM class used"?

Also consider reading the documentation at MSDN about Property Pages. https://docs.microsoft.com/en-us/windows/win32/com/property-sheets-and-property-pages

Oh yeah, couldn't your subclass just implement IDisposable? [Edit, Countryen: No, I don't think this will work, as I doubt that the Client will call Dispose, rather something like Marshal.ReleaseComObject() or IUnkwown::Release(), but the Finalizer should work.]

Any case, we appreciate it if you share the test results :)

Countryen avatar Aug 31 '19 18:08 Countryen