Hi,
please explain shortly how can continue run a code after calling the close method?
Eg: in a button action event in an embedded ContainerControl:
Cancelled = True
System.DebugLog( "in action before close" )
Self.Close
System.DebugLog( "in action after close" )
and in close event:
System.DebugLog( "in close handler before Cleanup" )
Window1( TrueWindow ).Cleanup
System.DebugLog( "in close handler after Cleanup" )
While I examine the debug log I see amazement there is life after death.
I do not understand how.
The calling a method not true jumping but just a message for object?
Only after dying when they were taken care of everything?
I’m not clear on the confusion. What was your expectation, that the code after Self.Close would not run? You’re still in that method so Close does whatever it’s going to do, then returns to the method that called it. If you tried to access controls within the ContainerControl after calling Close, you might run into some trouble, but your code as written doesn’t have an issue.
Calling ContainerControl.Close() does not mean “death”. Close() hides the container instance, then removes it from the window thereby also reducing the reference count by 1. If there are no other references to the container instance (reference count is 0), the destructor will be called and then this instance will be “dead”.
This is exciting, thank you!
This counter increasing too when I put it into an array?
Dim cc As New ContainerControl1
mConCons.Append( cc )
And decreases too in my celanup method when I remove it from array?
[code] // Remove completed or cancelled downloads
For i As Integer = mConCons.Ubound DownTo 0
If mConCons(i).Cancelled Then
// Adjust scroll bar height
Dim offset As Integer = mConCons.Ubound*mConCons(i).Height
DownloadScroller.Maximum = offset
// Remove downloader
mConCons(i).Close
mConCons.Remove(i)
End If
Yes, any reference will increase the internal reference count and keep it from being destroyed. This includes references by a property, variable, array, Dictionary, etc.
There are times when you may not want that. In those cases, you’d use a WeakRef which will let you access the object as long as it still exists .